Drop support for .NET Framework 4.8
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
||||||
<Version>0.1</Version>
|
<Version>0.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
+44
-62
@@ -145,30 +145,23 @@ namespace LibIRD
|
|||||||
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key));
|
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key));
|
||||||
|
|
||||||
// AES decryption
|
// AES decryption
|
||||||
using (Aes aes = Aes.Create())
|
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
|
||||||
{
|
|
||||||
// Validate aes is available
|
|
||||||
if (aes == null)
|
|
||||||
throw new InvalidOperationException("AES not available. Change your system settings");
|
|
||||||
|
|
||||||
// Set AES settings
|
// Set AES settings
|
||||||
aes.Key = D1AesKey;
|
aes.Key = D1AesKey;
|
||||||
aes.IV = D1AesIV;
|
aes.IV = D1AesIV;
|
||||||
aes.Padding = PaddingMode.None;
|
aes.Padding = PaddingMode.None;
|
||||||
aes.Mode = CipherMode.CBC;
|
aes.Mode = CipherMode.CBC;
|
||||||
|
|
||||||
// Perform AES decryption
|
// Perform AES decryption
|
||||||
using (ICryptoTransform decryptor = aes.CreateDecryptor())
|
using ICryptoTransform decryptor = aes.CreateDecryptor();
|
||||||
{
|
MemoryStream ms = new();
|
||||||
MemoryStream ms = new MemoryStream();
|
CryptoStream cs = new(ms, decryptor, CryptoStreamMode.Write);
|
||||||
CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write);
|
cs.Write(key, 0, 16);
|
||||||
cs.Write(key, 0, 16);
|
cs.FlushFinalBlock();
|
||||||
cs.FlushFinalBlock();
|
Data1Key = ms.ToArray();
|
||||||
Data1Key = ms.ToArray();
|
ms.Close();
|
||||||
ms.Close();
|
cs.Close();
|
||||||
cs.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -186,30 +179,23 @@ namespace LibIRD
|
|||||||
throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(id));
|
throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(id));
|
||||||
|
|
||||||
// AES encryption
|
// AES encryption
|
||||||
using (Aes aes = Aes.Create())
|
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
|
||||||
{
|
|
||||||
// Validate aes is available
|
|
||||||
if (aes == null)
|
|
||||||
throw new InvalidOperationException("AES not available. Change your system settings");
|
|
||||||
|
|
||||||
// Set AES settings
|
// Set AES settings
|
||||||
aes.Key = D2AesKey;
|
aes.Key = D2AesKey;
|
||||||
aes.IV = D2AesIV;
|
aes.IV = D2AesIV;
|
||||||
aes.Padding = PaddingMode.None;
|
aes.Padding = PaddingMode.None;
|
||||||
aes.Mode = CipherMode.CBC;
|
aes.Mode = CipherMode.CBC;
|
||||||
|
|
||||||
// Perform AES encryption
|
// Perform AES encryption
|
||||||
using (ICryptoTransform encryptor = aes.CreateEncryptor())
|
using ICryptoTransform encryptor = aes.CreateEncryptor();
|
||||||
{
|
MemoryStream ms = new();
|
||||||
MemoryStream ms = new MemoryStream();
|
CryptoStream cs = new(ms, encryptor, CryptoStreamMode.Write);
|
||||||
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
|
cs.Write(id, 0, 16);
|
||||||
cs.Write(id, 0, 16);
|
cs.FlushFinalBlock();
|
||||||
cs.FlushFinalBlock();
|
Data2Key = ms.ToArray();
|
||||||
Data2Key = ms.ToArray();
|
ms.Close();
|
||||||
ms.Close();
|
cs.Close();
|
||||||
cs.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -270,7 +256,7 @@ namespace LibIRD
|
|||||||
if (line == null)
|
if (line == null)
|
||||||
throw new InvalidDataException("Could not find Disc Key in .getkey.log");
|
throw new InvalidDataException("Could not find Disc Key in .getkey.log");
|
||||||
// Get Disc Key from log
|
// Get Disc Key from log
|
||||||
string discKeyStr = line.Substring("disc_key = ".Length);
|
string discKeyStr = line["disc_key = ".Length..];
|
||||||
// Validate Disc Key from log
|
// Validate Disc Key from log
|
||||||
if (discKeyStr.Length != 32)
|
if (discKeyStr.Length != 32)
|
||||||
throw new InvalidDataException("Unexpected Disc Key in .getkey.log");
|
throw new InvalidDataException("Unexpected Disc Key in .getkey.log");
|
||||||
@@ -282,12 +268,12 @@ namespace LibIRD
|
|||||||
if (line == null)
|
if (line == null)
|
||||||
throw new InvalidDataException("Could not find Disc ID in .getkey.log");
|
throw new InvalidDataException("Could not find Disc ID in .getkey.log");
|
||||||
// Get Disc ID from log
|
// Get Disc ID from log
|
||||||
string discIDStr = line.Substring("disc_id = ".Length);
|
string discIDStr = line["disc_id = ".Length..];
|
||||||
// Validate Disc ID from log
|
// Validate Disc ID from log
|
||||||
if (discIDStr.Length != 32)
|
if (discIDStr.Length != 32)
|
||||||
throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
|
throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
|
||||||
// Replace X's in Disc ID with 00000001
|
// Replace X's in Disc ID with 00000001
|
||||||
discIDStr = discIDStr.Substring(0, 24) + "00000001";
|
discIDStr = discIDStr[..24] + "00000001";
|
||||||
// Convert Disc ID to byte array
|
// Convert Disc ID to byte array
|
||||||
discID = Utilities.HexToBytes(discIDStr);
|
discID = Utilities.HexToBytes(discIDStr);
|
||||||
|
|
||||||
@@ -303,7 +289,7 @@ namespace LibIRD
|
|||||||
if (discPICStr.Length != 256)
|
if (discPICStr.Length != 256)
|
||||||
throw new InvalidDataException("Unexpected PIC in .getkey.log");
|
throw new InvalidDataException("Unexpected PIC in .getkey.log");
|
||||||
// Convert PIC to byte array
|
// Convert PIC to byte array
|
||||||
discPIC = Utilities.HexToBytes(discPICStr.Substring(0, 230));
|
discPIC = Utilities.HexToBytes(discPICStr[..230]);
|
||||||
|
|
||||||
// Check for warnings in .getkey.log
|
// Check for warnings in .getkey.log
|
||||||
while ((line = sr.ReadLine()) != null && line.Trim().StartsWith("WARNING") == false && line.Trim().StartsWith("SUCCESS") == false)
|
while ((line = sr.ReadLine()) != null && line.Trim().StartsWith("WARNING") == false && line.Trim().StartsWith("SUCCESS") == false)
|
||||||
@@ -337,10 +323,10 @@ namespace LibIRD
|
|||||||
throw new ArgumentNullException(nameof(irdPath));
|
throw new ArgumentNullException(nameof(irdPath));
|
||||||
|
|
||||||
// Create new stream to write to
|
// Create new stream to write to
|
||||||
Stream stream = new MemoryStream();
|
MemoryStream stream = new();
|
||||||
|
|
||||||
// Write IRD data to stream in order
|
// Write IRD data to stream in order
|
||||||
using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8, true))
|
using (BinaryWriter bw = new(stream, Encoding.UTF8, true))
|
||||||
{
|
{
|
||||||
// IRD File Signature
|
// IRD File Signature
|
||||||
bw.Write(Magic);
|
bw.Write(Magic);
|
||||||
@@ -426,7 +412,7 @@ namespace LibIRD
|
|||||||
|
|
||||||
// Calculate the little-endian 32-bit "IEEE 802.3" CRC value of the entire stream
|
// Calculate the little-endian 32-bit "IEEE 802.3" CRC value of the entire stream
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
Crc32 crc32 = new Crc32();
|
Crc32 crc32 = new();
|
||||||
crc32.Append(stream);
|
crc32.Append(stream);
|
||||||
byte[] crc = crc32.GetCurrentHash();
|
byte[] crc = crc32.GetCurrentHash();
|
||||||
|
|
||||||
@@ -434,17 +420,13 @@ namespace LibIRD
|
|||||||
stream.Write(crc, 0, 4);
|
stream.Write(crc, 0, 4);
|
||||||
|
|
||||||
// Create the IRD file stream
|
// Create the IRD file stream
|
||||||
using (FileStream fs = new FileStream(irdPath, FileMode.Create, FileAccess.Write))
|
using FileStream fs = new(irdPath, FileMode.Create, FileAccess.Write);
|
||||||
{
|
// Create a GZipped IRD file stream
|
||||||
// Create a GZipped IRD file stream
|
using GZipStream gzStream = new(fs, CompressionLevel.SmallestSize);
|
||||||
using (GZipStream gzStream = new GZipStream(fs, CompressionLevel.Optimal))
|
// Write entire gzipped IRD stream to file
|
||||||
{
|
stream.Position = 0;
|
||||||
// Write entire gzipped IRD stream to file
|
stream.CopyTo(gzStream);
|
||||||
stream.Position = 0;
|
stream.Close();
|
||||||
stream.CopyTo(gzStream);
|
|
||||||
stream.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
||||||
<Version>0.1</Version>
|
<Version>0.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
+81
-87
@@ -3,7 +3,6 @@ using DiscUtils.Iso9660;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace LibIRD
|
namespace LibIRD
|
||||||
@@ -138,7 +137,7 @@ namespace LibIRD
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fs"></param>
|
/// <param name="fs"></param>
|
||||||
/// <param name="reader"></param>
|
/// <param name="reader"></param>
|
||||||
private void GetSystemVersion(Stream fs, CDReader reader)
|
private void GetSystemVersion(FileStream fs, CDReader reader)
|
||||||
{
|
{
|
||||||
|
|
||||||
//DiscUtils.Streams.StreamExtent[] a = reader.PathToExtents("\\PS3_UPDATE\\PS3UPDAT.PUP");
|
//DiscUtils.Streams.StreamExtent[] a = reader.PathToExtents("\\PS3_UPDATE\\PS3UPDAT.PUP");
|
||||||
@@ -205,94 +204,89 @@ namespace LibIRD
|
|||||||
FileHashes[i] = NullMD5;
|
FileHashes[i] = NullMD5;
|
||||||
|
|
||||||
// Process ISO file
|
// Process ISO file
|
||||||
using (Stream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read))
|
using FileStream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(isoPath);
|
||||||
|
// Validate ISO file
|
||||||
|
if (!CDReader.Detect(fs))
|
||||||
|
throw new InvalidDataException("Not a valid ISO file");
|
||||||
|
|
||||||
|
// New ISO Reader from DiscUtils
|
||||||
|
CDReader reader = new(fs, true, true);
|
||||||
|
|
||||||
|
// Read PS3 Metadata from PARAM.SFO
|
||||||
|
using (DiscUtils.Streams.SparseStream s = reader.OpenFile("PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
|
||||||
{
|
{
|
||||||
// Validate ISO filestream
|
// Parse PARAM.SFO file
|
||||||
if (fs == null)
|
ParamSFO paramSFO = new(s);
|
||||||
throw new ArgumentNullException("Failed to open ISO");
|
|
||||||
if (!CDReader.Detect(fs))
|
|
||||||
throw new InvalidDataException("Not a valid ISO file");
|
|
||||||
|
|
||||||
// New ISO Reader from DiscUtils
|
|
||||||
CDReader reader = new CDReader(fs, true, true);
|
|
||||||
|
|
||||||
// Read PS3 Metadata from PARAM.SFO
|
|
||||||
using (Stream s = reader.OpenFile("PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
// Parse PARAM.SFO file
|
|
||||||
ParamSFO paramSFO = new ParamSFO(s);
|
|
||||||
|
|
||||||
// Store required values for IRD
|
|
||||||
TitleID = paramSFO["TITLE_ID"];
|
|
||||||
Title = paramSFO["TITLE"];
|
|
||||||
GameVersion = paramSFO["VERSION"];
|
|
||||||
AppVersion = paramSFO["APP_VER"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine system update version
|
|
||||||
GetSystemVersion(fs, reader);
|
|
||||||
|
|
||||||
|
|
||||||
// Determine the extent of the Header (Sector 0 to first data sector)
|
|
||||||
//DiscUtils.Streams.Range<long, long> clusters = reader.PathToClusters("\\").First();
|
|
||||||
//long firstSector = clusters.Offset;
|
|
||||||
//long totalSectors = (long) Math.Ceiling(clusters.Count / 2048.0);
|
|
||||||
|
|
||||||
// Compress the header and store
|
|
||||||
DiscUtils.Streams.Range<long, long>[] sfbClusters = reader.PathToClusters("\\PS3_DISC.SFB");
|
|
||||||
long firstSector = sfbClusters[0] != null ? sfbClusters[0].Offset : 0;
|
|
||||||
using (MemoryStream headerStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (GZipStream gzs = new GZipStream(headerStream, CompressionLevel.Optimal))
|
|
||||||
{
|
|
||||||
fs.Seek(0, SeekOrigin.Begin);
|
|
||||||
byte[] buf = new byte[2048];
|
|
||||||
// Read all sectors before the first data sector
|
|
||||||
for (int i = 0; i < firstSector; i++)
|
|
||||||
{
|
|
||||||
int numBytes = fs.Read(buf, 0, buf.Length);
|
|
||||||
gzs.Write(buf, 0, numBytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Header = headerStream.ToArray();
|
|
||||||
HeaderLength = (uint) Header.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compress the footer and store
|
|
||||||
DiscUtils.Streams.StreamExtent[] updateBytes = reader.PathToExtents("\\PS3_UPDATE\\PS3UPDAT.PUP");
|
|
||||||
// TODO: check if updateBytes array is not empty?
|
|
||||||
long lastByte = updateBytes[updateBytes.Length - 1].Start + updateBytes[updateBytes.Length - 1].Length;
|
|
||||||
using (MemoryStream footerStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (GZipStream gzs = new GZipStream(footerStream, CompressionLevel.Optimal))
|
|
||||||
{
|
|
||||||
// Start saving data from after last file
|
|
||||||
fs.Seek(lastByte, SeekOrigin.Begin);
|
|
||||||
byte[] buf = new byte[2048];
|
|
||||||
int numBytes = 2048;
|
|
||||||
// Keep reading data until there is none left to read
|
|
||||||
while (numBytes != 0)
|
|
||||||
{
|
|
||||||
numBytes = fs.Read(buf, 0, buf.Length);
|
|
||||||
gzs.Write(buf, 0, numBytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Footer = footerStream.ToArray();
|
|
||||||
FooterLength = (uint) Footer.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get info on root directory
|
|
||||||
//DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
|
|
||||||
// Recursively process all subdirectories
|
|
||||||
ParseDir(reader, "\\");
|
|
||||||
|
|
||||||
// Calculate last sector
|
|
||||||
//DiscDirectoryInfo lastFile = reader.
|
|
||||||
//lastSector = lastFile.StartSector + lastFile.TotalSectors;
|
|
||||||
|
|
||||||
|
// Store required values for IRD
|
||||||
|
TitleID = paramSFO["TITLE_ID"];
|
||||||
|
Title = paramSFO["TITLE"];
|
||||||
|
GameVersion = paramSFO["VERSION"];
|
||||||
|
AppVersion = paramSFO["APP_VER"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine system update version
|
||||||
|
GetSystemVersion(fs, reader);
|
||||||
|
|
||||||
|
|
||||||
|
// Determine the extent of the Header (Sector 0 to first data sector)
|
||||||
|
//DiscUtils.Streams.Range<long, long> clusters = reader.PathToClusters("\\").First();
|
||||||
|
//long firstSector = clusters.Offset;
|
||||||
|
//long totalSectors = (long) Math.Ceiling(clusters.Count / 2048.0);
|
||||||
|
|
||||||
|
// Compress the header and store
|
||||||
|
DiscUtils.Streams.Range<long, long>[] sfbClusters = reader.PathToClusters("\\PS3_DISC.SFB");
|
||||||
|
long firstSector = sfbClusters[0] != null ? sfbClusters[0].Offset : 0;
|
||||||
|
using (MemoryStream headerStream = new())
|
||||||
|
{
|
||||||
|
using (GZipStream gzs = new(headerStream, CompressionLevel.SmallestSize))
|
||||||
|
{
|
||||||
|
fs.Seek(0, SeekOrigin.Begin);
|
||||||
|
byte[] buf = new byte[2048];
|
||||||
|
// Read all sectors before the first data sector
|
||||||
|
for (int i = 0; i < firstSector; i++)
|
||||||
|
{
|
||||||
|
int numBytes = fs.Read(buf, 0, buf.Length);
|
||||||
|
gzs.Write(buf, 0, numBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Header = headerStream.ToArray();
|
||||||
|
HeaderLength = (uint)Header.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compress the footer and store
|
||||||
|
DiscUtils.Streams.StreamExtent[] updateBytes = reader.PathToExtents("\\PS3_UPDATE\\PS3UPDAT.PUP");
|
||||||
|
long lastByte = updateBytes[^1].Start + updateBytes[^1].Length;
|
||||||
|
using (MemoryStream footerStream = new())
|
||||||
|
{
|
||||||
|
using (GZipStream gzs = new(footerStream, CompressionLevel.SmallestSize))
|
||||||
|
{
|
||||||
|
// Start saving data from after last file
|
||||||
|
fs.Seek(lastByte, SeekOrigin.Begin);
|
||||||
|
byte[] buf = new byte[2048];
|
||||||
|
int numBytes = 2048;
|
||||||
|
// Keep reading data until there is none left to read
|
||||||
|
while (numBytes != 0)
|
||||||
|
{
|
||||||
|
numBytes = fs.Read(buf, 0, buf.Length);
|
||||||
|
gzs.Write(buf, 0, numBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Footer = footerStream.ToArray();
|
||||||
|
FooterLength = (uint)Footer.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Get info on root directory
|
||||||
|
//DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
|
||||||
|
// Recursively process all subdirectories
|
||||||
|
ParseDir(reader, "\\");
|
||||||
|
|
||||||
|
// Calculate last sector
|
||||||
|
//DiscDirectoryInfo lastFile = reader.
|
||||||
|
//lastSector = lastFile.StartSector + lastFile.TotalSectors;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
|
||||||
<Version>0.1</Version>
|
<Version>0.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user