diff --git a/SabreTools.Serialization/Extensions/CDROM.cs b/SabreTools.Serialization/Extensions/CDROM.cs
index 0c38a23b..b41dd6e5 100644
--- a/SabreTools.Serialization/Extensions/CDROM.cs
+++ b/SabreTools.Serialization/Extensions/CDROM.cs
@@ -138,24 +138,15 @@ namespace SabreTools.Data.Extensions
///
public override long Length
- {
- get
- {
- return (_baseStream.Length / Constants.CDROMSectorSize) * _isoSectorSize;
- }
- }
+ => (_baseStream.Length / Constants.CDROMSectorSize) * _isoSectorSize;
///
public override void SetLength(long value)
- {
- throw new NotSupportedException("Setting the length of this stream is not supported.");
- }
+ => throw new NotSupportedException("Setting the length of this stream is not supported.");
///
public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotSupportedException("Writing to this stream is not supported.");
- }
+ => throw new NotSupportedException("Writing to this stream is not supported.");
///
protected override void Dispose(bool disposing)
diff --git a/SabreTools.Serialization/Extensions/PortableExecutable.cs b/SabreTools.Serialization/Extensions/PortableExecutable.cs
index 608444de..81c6cac4 100644
--- a/SabreTools.Serialization/Extensions/PortableExecutable.cs
+++ b/SabreTools.Serialization/Extensions/PortableExecutable.cs
@@ -18,10 +18,10 @@ namespace SabreTools.Data.Extensions
/// Relative virtual address to convert
/// Array of sections to check against
/// Physical address, 0 on error
- public static uint ConvertVirtualAddress(this uint rva, SectionHeader[]? sections)
+ public static uint ConvertVirtualAddress(this uint rva, SectionHeader[] sections)
{
// If we have an invalid section table, we can't do anything
- if (sections == null || sections.Length == 0)
+ if (sections.Length == 0)
return 0;
// If the RVA is 0, we just return 0 because it's invalid
@@ -69,7 +69,7 @@ namespace SabreTools.Data.Extensions
/// Relative virtual address to convert
/// Array of sections to check against
/// Section index, null on error
- public static int ContainingSectionIndex(this uint rva, SectionHeader[]? sections)
+ public static int ContainingSectionIndex(this uint rva, SectionHeader[] sections)
{
// If we have an invalid section table, we can't do anything
if (sections == null || sections.Length == 0)
@@ -1282,10 +1282,10 @@ namespace SabreTools.Data.Extensions
/// Data to parse
/// Offset into the byte array
/// A filled ResourceHeader on success, null on error
- public static Data.Models.PortableExecutable.Resource.ResourceHeader ParseResourceHeader(this byte[] data, ref int offset)
+ public static Models.PortableExecutable.Resource.ResourceHeader ParseResourceHeader(this byte[] data, ref int offset)
{
// Read in the table
- var obj = new Data.Models.PortableExecutable.Resource.ResourceHeader();
+ var obj = new Models.PortableExecutable.Resource.ResourceHeader();
obj.DataSize = data.ReadUInt32LittleEndian(ref offset);
obj.HeaderSize = data.ReadUInt32LittleEndian(ref offset);
diff --git a/SabreTools.Serialization/Extensions/TypeLengthValue.cs b/SabreTools.Serialization/Extensions/TypeLengthValue.cs
index 93fbb23d..ffcb1b67 100644
--- a/SabreTools.Serialization/Extensions/TypeLengthValue.cs
+++ b/SabreTools.Serialization/Extensions/TypeLengthValue.cs
@@ -13,7 +13,7 @@ namespace SabreTools.Data.Extensions
///
/// Padding level of the item when formatting
/// String representing the TypeLengthValue, if possible
- public static string Format(this Data.Models.ASN1.TypeLengthValue tlv, int paddingLevel = 0)
+ public static string Format(this Models.ASN1.TypeLengthValue tlv, int paddingLevel = 0)
{
// Create the left-padding string
string padding = new(' ', paddingLevel);
@@ -38,7 +38,7 @@ namespace SabreTools.Data.Extensions
if (tlv.Type.HasFlag(ASN1Type.V_ASN1_CONSTRUCTED))
#endif
{
- if (tlv.Value is not SabreTools.Data.Models.ASN1.TypeLengthValue[] valueAsObjectArray)
+ if (tlv.Value is not Models.ASN1.TypeLengthValue[] valueAsObjectArray)
{
formatBuilder.Append(", Value: [INVALID DATA TYPE]");
return formatBuilder.ToString();
diff --git a/SabreTools.Serialization/Readers/AACS.cs b/SabreTools.Serialization/Readers/AACS.cs
index 2744fb68..461716d1 100644
--- a/SabreTools.Serialization/Readers/AACS.cs
+++ b/SabreTools.Serialization/Readers/AACS.cs
@@ -65,9 +65,7 @@ namespace SabreTools.Serialization.Readers
private static Record? ParseRecord(Stream data)
{
// The first 4 bytes are the type and length
- RecordType type = (RecordType)data.ReadByteValue();
- uint recordLength = data.ReadUInt24LittleEndian();
- data.SeekIfPossible(-4, SeekOrigin.Current);
+ RecordType type = (RecordType)data.PeekByteValue();
// Create a record based on the type
return type switch
diff --git a/SabreTools.Serialization/Readers/PortableExecutable.cs b/SabreTools.Serialization/Readers/PortableExecutable.cs
index c501da43..8afedbda 100644
--- a/SabreTools.Serialization/Readers/PortableExecutable.cs
+++ b/SabreTools.Serialization/Readers/PortableExecutable.cs
@@ -293,6 +293,7 @@ namespace SabreTools.Serialization.Readers
#endregion
+ // TODO: Pre-parse known resource types
#region Resource Directory Table
// Should also be in a '.rsrc' section
diff --git a/SabreTools.Serialization/Wrappers/CFB.Extraction.cs b/SabreTools.Serialization/Wrappers/CFB.Extraction.cs
index c7ad5146..3296e3da 100644
--- a/SabreTools.Serialization/Wrappers/CFB.Extraction.cs
+++ b/SabreTools.Serialization/Wrappers/CFB.Extraction.cs
@@ -2,7 +2,7 @@ using System;
using System.IO;
using System.Text;
using SabreTools.Data.Models.CFB;
-#if NETFRAMEWORK || NETSTANDARD
+#if NETFRAMEWORK || NETSTANDARD2_0
using SabreTools.IO.Extensions;
#endif
diff --git a/SabreTools.Serialization/Wrappers/CHD.Printing.cs b/SabreTools.Serialization/Wrappers/CHD.Printing.cs
index b806ae6f..d7d15f22 100644
--- a/SabreTools.Serialization/Wrappers/CHD.Printing.cs
+++ b/SabreTools.Serialization/Wrappers/CHD.Printing.cs
@@ -37,7 +37,7 @@ namespace SabreTools.Serialization.Wrappers
Print(builder, v5);
break;
default:
- builder.AppendLine("Unrecognized header type");
+ builder.AppendLine($"Unrecognized header type: {Model}");
builder.AppendLine();
break;
}
diff --git a/SabreTools.Serialization/Wrappers/IExtractable.cs b/SabreTools.Serialization/Wrappers/IExtractable.cs
index f64a8af4..70e55216 100644
--- a/SabreTools.Serialization/Wrappers/IExtractable.cs
+++ b/SabreTools.Serialization/Wrappers/IExtractable.cs
@@ -3,6 +3,7 @@ namespace SabreTools.Serialization.Wrappers
///
/// Represents an item that is extractable
///
+ /// TODO: Investigate whether it's possible to do an ExtractToStream
public interface IExtractable
{
///
diff --git a/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs b/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs
index 3cc0de5c..5b30b5b8 100644
--- a/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs
+++ b/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs
@@ -31,9 +31,9 @@ namespace SabreTools.Serialization.Wrappers
Print(builder, Model.DirectoryDescriptors, encoding);
}
- protected static void Print(StringBuilder builder, byte[]? systemArea)
+ protected static void Print(StringBuilder builder, byte[] systemArea)
{
- if (systemArea == null || systemArea.Length == 0)
+ if (systemArea.Length == 0)
builder.AppendLine(systemArea, " System Area");
else if (Array.TrueForAll(systemArea, b => b == 0))
builder.AppendLine("Zeroed", " System Area");
diff --git a/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs b/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs
index 5ed72b6b..b421db34 100644
--- a/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs
+++ b/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs
@@ -94,8 +94,6 @@ namespace SabreTools.Serialization.Wrappers
return field;
}
-
- private set;
} = null;
///
diff --git a/SabreTools.Serialization/Wrappers/N3DS.cs b/SabreTools.Serialization/Wrappers/N3DS.cs
index c2e9c1c4..fa7f8fd0 100644
--- a/SabreTools.Serialization/Wrappers/N3DS.cs
+++ b/SabreTools.Serialization/Wrappers/N3DS.cs
@@ -51,7 +51,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionsTable.Length == 0)
+ if (PartitionsTable.Length < 1)
return null;
return PartitionsTable[0];
@@ -65,7 +65,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionsTable.Length == 0)
+ if (PartitionsTable.Length < 2)
return null;
return PartitionsTable[1];
@@ -79,7 +79,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionsTable.Length == 0)
+ if (PartitionsTable.Length < 3)
return null;
return PartitionsTable[2];
@@ -93,7 +93,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionsTable.Length == 0)
+ if (PartitionsTable.Length < 7)
return null;
return PartitionsTable[6];
@@ -107,7 +107,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionsTable.Length == 0)
+ if (PartitionsTable.Length < 8)
return null;
return PartitionsTable[7];
@@ -131,7 +131,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionFlags.Length == 0)
+ if (PartitionFlags.Length < (int)NCSDFlags.BackupWriteWaitTime + 1)
return default;
return PartitionFlags[(int)NCSDFlags.BackupWriteWaitTime];
@@ -145,7 +145,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionFlags.Length == 0)
+ if (PartitionFlags.Length < (int)NCSDFlags.MediaCardDevice2X + 1)
return default;
return (MediaCardDeviceType)PartitionFlags[(int)NCSDFlags.MediaCardDevice2X];
@@ -159,7 +159,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionFlags.Length == 0)
+ if (PartitionFlags.Length < (int)NCSDFlags.MediaCardDevice3X + 1)
return default;
return (MediaCardDeviceType)PartitionFlags[(int)NCSDFlags.MediaCardDevice3X];
@@ -173,7 +173,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionFlags.Length == 0)
+ if (PartitionFlags.Length < (int)NCSDFlags.MediaPlatformIndex + 1)
return default;
return (MediaPlatformIndex)PartitionFlags[(int)NCSDFlags.MediaPlatformIndex];
@@ -187,7 +187,7 @@ namespace SabreTools.Serialization.Wrappers
{
get
{
- if (PartitionFlags.Length == 0)
+ if (PartitionFlags.Length < (int)NCSDFlags.MediaTypeIndex + 1)
return default;
return (MediaTypeIndex)PartitionFlags[(int)NCSDFlags.MediaTypeIndex];
diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs
index 3311699a..0d6ab1d3 100644
--- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs
+++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
-#if NET462_OR_GREATER || NETCOREAPP
+#if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
using SharpCompress.Readers;
@@ -22,7 +22,7 @@ namespace SabreTools.Serialization.Wrappers
if (_dataSource == null || !_dataSource.CanRead)
return false;
-#if NET462_OR_GREATER || NETCOREAPP
+#if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
@@ -74,17 +74,17 @@ namespace SabreTools.Serialization.Wrappers
entry.WriteToFile(filename);
}
- catch (System.Exception ex)
+ catch (Exception ex)
{
- if (includeDebug) System.Console.Error.WriteLine(ex);
+ if (includeDebug) Console.Error.WriteLine(ex);
}
}
return true;
}
- catch (System.Exception ex)
+ catch (Exception ex)
{
- if (includeDebug) System.Console.Error.WriteLine(ex);
+ if (includeDebug) Console.Error.WriteLine(ex);
return false;
}
#else
diff --git a/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs b/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs
index a4d4b928..19c6a455 100644
--- a/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs
+++ b/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs
@@ -259,7 +259,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, SectionHeader[]? entries)
+ private static void Print(StringBuilder builder, SectionHeader[] entries)
{
builder.AppendLine(" Section Table Information:");
builder.AppendLine(" -------------------------");
@@ -431,7 +431,7 @@ namespace SabreTools.Serialization.Wrappers
}
// Create the deserializer
- var deserializer = new Serialization.Readers.AbstractSyntaxNotationOne();
+ var deserializer = new Readers.AbstractSyntaxNotationOne();
for (int i = 0; i < entries.Length; i++)
{
@@ -486,7 +486,7 @@ namespace SabreTools.Serialization.Wrappers
}
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.DelayLoad.DirectoryTable? table, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.DelayLoad.DirectoryTable? table, SectionHeader[] sections)
{
builder.AppendLine(" Delay-Load Directory Table Information:");
builder.AppendLine(" -------------------------");
@@ -513,7 +513,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.BaseRelocation.Block[]? entries, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.BaseRelocation.Block[]? entries, SectionHeader[] sections)
{
builder.AppendLine(" Base Relocation Table Information:");
builder.AppendLine(" -------------------------");
@@ -585,7 +585,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.DirectoryTable? table, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.DirectoryTable? table, SectionHeader[] sections)
{
builder.AppendLine(value: " Export Directory Table Information:");
builder.AppendLine(" -------------------------");
@@ -615,7 +615,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.AddressTableEntry[]? table, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.AddressTableEntry[]? table, SectionHeader[] sections)
{
builder.AppendLine(" Export Address Table Information:");
builder.AppendLine(" -------------------------");
@@ -704,7 +704,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Import.DirectoryTableEntry[]? table, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Import.DirectoryTableEntry[]? table, SectionHeader[] sections)
{
builder.AppendLine(" Import Directory Table Information:");
builder.AppendLine(" -------------------------");
@@ -734,7 +734,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[] sections)
{
builder.AppendLine(" Import Lookup Tables Information:");
builder.AppendLine(" -------------------------");
@@ -780,7 +780,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[] sections)
{
builder.AppendLine(" Import Address Tables Information:");
builder.AppendLine(" -------------------------");
@@ -849,7 +849,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryTable? table, SectionHeader[]? sections)
+ private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryTable? table, SectionHeader[] sections)
{
builder.AppendLine(" Resource Directory Table Information:");
builder.AppendLine(" -------------------------");
@@ -864,7 +864,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
- private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryTable table, int level, List