Skip to content

Commit

Permalink
support discs without the license file
Browse files Browse the repository at this point in the history
  • Loading branch information
13xforever committed Apr 2, 2019
1 parent 0c1ba06 commit 7057aa6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
52 changes: 27 additions & 25 deletions Ps3DiscDumper/Dumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DiscUtils.Iso9660;
using IrdLibraryClient;
using IrdLibraryClient.IrdFormat;
using IrdLibraryClient.POCOs;
using Ps3DiscDumper.DiscInfo;
using Ps3DiscDumper.DiscKeyProviders;
using Ps3DiscDumper.Sfb;
Expand All @@ -30,8 +28,13 @@ public class Dumper: IDisposable
private static readonly Dictionary<string, HashSet<DiscKeyInfo>> AllKnownDiscKeys = new Dictionary<string, HashSet<DiscKeyInfo>>();
private readonly HashSet<string> TestedDiscKeys = new HashSet<string>();
private byte[] discSfbData;
private static readonly byte[] LicenseMagic = Encoding.UTF8.GetBytes("PS3LICDA");
private byte[] licSector;
private static readonly Dictionary<string, byte[]> Detectors = new Dictionary<string, byte[]>
{
[@"\PS3_GAME\LICDIR\LIC.DAT"] = Encoding.UTF8.GetBytes("PS3LICDA"),
[@"\PS3_GAME\USRDIR\EBOOT.BIN"] = Encoding.UTF8.GetBytes("SCE").Concat(new byte[] { 0, 0, 0, 0, 2 }).ToArray(),
};
private byte[] detectionSector;
private byte[] detectionBytesExpected;
private byte[] sectorIV;
private Stream driveStream;

Expand Down Expand Up @@ -282,36 +285,36 @@ public async Task FindDiscKeyAsync(string discKeyCachePath)

// find disc license file
discReader = new CDReader(driveStream, true, true);
FileRecord licInfo = null;
FileRecord detectionRecord = null;
byte[] expectedBytes = null;
try
{
var licPath = @"\PS3_GAME\LICDIR\LIC.DAT";
if (discReader.FileExists(licPath))
{
var clusterRange = discReader.PathToClusters(licPath);
licInfo = new FileRecord(licPath, clusterRange.Min(r => r.Offset), discReader.GetFileLength(licPath));
}
else
{
filesystemStructure = discReader.GetFilesystemStructure();
licInfo = filesystemStructure.FirstOrDefault(fr => fr.Filename.EndsWith("LICDIR\\LIC.DAT"));
}
foreach (var path in Detectors.Keys)
if (discReader.FileExists(path))
{
var clusterRange = discReader.PathToClusters(path);
detectionRecord = new FileRecord(path, clusterRange.Min(r => r.Offset), discReader.GetFileLength(path));
expectedBytes = Detectors[path];
Log.Debug($"Using {path} for disc key detection");
break;
}
}
catch (Exception e)
{
Log.Error(e);
}
if (licInfo == null)
throw new FileNotFoundException("Couldn't find a single disc license file, please report");
if (detectionRecord == null)
throw new FileNotFoundException("Couldn't find a single disc key detection file, please report");

if (Cts.IsCancellationRequested)
return;

// select decryption key
driveStream.Seek(licInfo.StartSector * discReader.ClusterSize, SeekOrigin.Begin);
licSector = new byte[discReader.ClusterSize];
sectorIV = Decrypter.GetSectorIV(licInfo.StartSector);
driveStream.ReadExact(licSector, 0, licSector.Length);
driveStream.Seek(detectionRecord.StartSector * discReader.ClusterSize, SeekOrigin.Begin);
detectionSector = new byte[discReader.ClusterSize];
detectionBytesExpected = expectedBytes;
sectorIV = Decrypter.GetSectorIV(detectionRecord.StartSector);
driveStream.ReadExact(detectionSector, 0, detectionSector.Length);
string discKey = null;
try
{
Expand Down Expand Up @@ -482,9 +485,8 @@ private bool IsValidDiscKey(string discKeyId)

public bool IsValidDiscKey(byte[] discKey)
{
var licBytes = Decrypter.DecryptSector(discKey, licSector, sectorIV);

return licBytes.Take(LicenseMagic.Length).SequenceEqual(LicenseMagic);
var licBytes = Decrypter.DecryptSector(discKey, detectionSector, sectorIV);
return licBytes.Take(detectionBytesExpected.Length).SequenceEqual(detectionBytesExpected);

}

Expand Down
2 changes: 1 addition & 1 deletion UI.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class Program
{
static async Task Main(string[] args)
{
Log.Info("PS3 Disc Dumper v1.1.2");
Log.Info("PS3 Disc Dumper v3.0.1");
var lastDiscId = "";
start:
const string titleBase = "PS3 Disc Dumper";
Expand Down
2 changes: 1 addition & 1 deletion UI.WinForms.Msil/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7057aa6

Please sign in to comment.