Drop support for .NET Framework 4.8

This commit is contained in:
Deterous
2023-11-01 17:16:38 +13:00
parent c57c58d633
commit 743f3210a3
5 changed files with 129 additions and 153 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<Version>0.1</Version>
</PropertyGroup>
+17 -35
View File
@@ -145,11 +145,7 @@ namespace LibIRD
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key));
// AES decryption
using (Aes aes = Aes.Create())
{
// Validate aes is available
if (aes == null)
throw new InvalidOperationException("AES not available. Change your system settings");
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
// Set AES settings
aes.Key = D1AesKey;
@@ -158,18 +154,15 @@ namespace LibIRD
aes.Mode = CipherMode.CBC;
// Perform AES decryption
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write);
using ICryptoTransform decryptor = aes.CreateDecryptor();
MemoryStream ms = new();
CryptoStream cs = new(ms, decryptor, CryptoStreamMode.Write);
cs.Write(key, 0, 16);
cs.FlushFinalBlock();
Data1Key = ms.ToArray();
ms.Close();
cs.Close();
}
}
}
/// <summary>
/// Generates Data 2, via AES-128 CBC encryption of a Disc ID
@@ -186,11 +179,7 @@ namespace LibIRD
throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(id));
// AES encryption
using (Aes aes = Aes.Create())
{
// Validate aes is available
if (aes == null)
throw new InvalidOperationException("AES not available. Change your system settings");
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
// Set AES settings
aes.Key = D2AesKey;
@@ -199,18 +188,15 @@ namespace LibIRD
aes.Mode = CipherMode.CBC;
// Perform AES encryption
using (ICryptoTransform encryptor = aes.CreateEncryptor())
{
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
using ICryptoTransform encryptor = aes.CreateEncryptor();
MemoryStream ms = new();
CryptoStream cs = new(ms, encryptor, CryptoStreamMode.Write);
cs.Write(id, 0, 16);
cs.FlushFinalBlock();
Data2Key = ms.ToArray();
ms.Close();
cs.Close();
}
}
}
#endregion
@@ -270,7 +256,7 @@ namespace LibIRD
if (line == null)
throw new InvalidDataException("Could not find Disc Key in .getkey.log");
// Get Disc Key from log
string discKeyStr = line.Substring("disc_key = ".Length);
string discKeyStr = line["disc_key = ".Length..];
// Validate Disc Key from log
if (discKeyStr.Length != 32)
throw new InvalidDataException("Unexpected Disc Key in .getkey.log");
@@ -282,12 +268,12 @@ namespace LibIRD
if (line == null)
throw new InvalidDataException("Could not find Disc ID in .getkey.log");
// Get Disc ID from log
string discIDStr = line.Substring("disc_id = ".Length);
string discIDStr = line["disc_id = ".Length..];
// Validate Disc ID from log
if (discIDStr.Length != 32)
throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
// Replace X's in Disc ID with 00000001
discIDStr = discIDStr.Substring(0, 24) + "00000001";
discIDStr = discIDStr[..24] + "00000001";
// Convert Disc ID to byte array
discID = Utilities.HexToBytes(discIDStr);
@@ -303,7 +289,7 @@ namespace LibIRD
if (discPICStr.Length != 256)
throw new InvalidDataException("Unexpected PIC in .getkey.log");
// Convert PIC to byte array
discPIC = Utilities.HexToBytes(discPICStr.Substring(0, 230));
discPIC = Utilities.HexToBytes(discPICStr[..230]);
// Check for warnings in .getkey.log
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));
// Create new stream to write to
Stream stream = new MemoryStream();
MemoryStream stream = new();
// 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
bw.Write(Magic);
@@ -426,7 +412,7 @@ namespace LibIRD
// Calculate the little-endian 32-bit "IEEE 802.3" CRC value of the entire stream
stream.Position = 0;
Crc32 crc32 = new Crc32();
Crc32 crc32 = new();
crc32.Append(stream);
byte[] crc = crc32.GetCurrentHash();
@@ -434,18 +420,14 @@ namespace LibIRD
stream.Write(crc, 0, 4);
// 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
using (GZipStream gzStream = new GZipStream(fs, CompressionLevel.Optimal))
{
using GZipStream gzStream = new(fs, CompressionLevel.SmallestSize);
// Write entire gzipped IRD stream to file
stream.Position = 0;
stream.CopyTo(gzStream);
stream.Close();
}
}
}
#endregion
}
+1 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<Version>0.1</Version>
</PropertyGroup>
+13 -19
View File
@@ -3,7 +3,6 @@ using DiscUtils.Iso9660;
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
namespace LibIRD
@@ -138,7 +137,7 @@ namespace LibIRD
/// </summary>
/// <param name="fs"></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");
@@ -205,22 +204,19 @@ namespace LibIRD
FileHashes[i] = NullMD5;
// Process ISO file
using (Stream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read))
{
// Validate ISO filestream
if (fs == null)
throw new ArgumentNullException("Failed to open ISO");
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 CDReader(fs, true, true);
CDReader reader = new(fs, true, true);
// Read PS3 Metadata from PARAM.SFO
using (Stream s = reader.OpenFile("PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
using (DiscUtils.Streams.SparseStream s = reader.OpenFile("PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
{
// Parse PARAM.SFO file
ParamSFO paramSFO = new ParamSFO(s);
ParamSFO paramSFO = new(s);
// Store required values for IRD
TitleID = paramSFO["TITLE_ID"];
@@ -241,9 +237,9 @@ namespace LibIRD
// 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 (MemoryStream headerStream = new())
{
using (GZipStream gzs = new GZipStream(headerStream, CompressionLevel.Optimal))
using (GZipStream gzs = new(headerStream, CompressionLevel.SmallestSize))
{
fs.Seek(0, SeekOrigin.Begin);
byte[] buf = new byte[2048];
@@ -255,16 +251,15 @@ namespace LibIRD
}
}
Header = headerStream.ToArray();
HeaderLength = (uint) Header.Length;
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())
long lastByte = updateBytes[^1].Start + updateBytes[^1].Length;
using (MemoryStream footerStream = new())
{
using (GZipStream gzs = new GZipStream(footerStream, CompressionLevel.Optimal))
using (GZipStream gzs = new(footerStream, CompressionLevel.SmallestSize))
{
// Start saving data from after last file
fs.Seek(lastByte, SeekOrigin.Begin);
@@ -278,7 +273,7 @@ namespace LibIRD
}
}
Footer = footerStream.ToArray();
FooterLength = (uint) Footer.Length;
FooterLength = (uint)Footer.Length;
}
@@ -294,5 +289,4 @@ namespace LibIRD
}
}
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<Version>0.1</Version>
</PropertyGroup>