Skip to content

Commit f6201e2

Browse files
committed
In-depth cleanup with .NET 10 concepts
1 parent d63fcfc commit f6201e2

31 files changed

+412
-198
lines changed

SabreTools.Serialization/Extensions/CDROM.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,15 @@ public ISO9660Stream(Stream inputStream)
138138

139139
/// <inheritdoc/>
140140
public override long Length
141-
{
142-
get
143-
{
144-
return (_baseStream.Length / Constants.CDROMSectorSize) * _isoSectorSize;
145-
}
146-
}
141+
=> (_baseStream.Length / Constants.CDROMSectorSize) * _isoSectorSize;
147142

148143
/// <inheritdoc/>
149144
public override void SetLength(long value)
150-
{
151-
throw new NotSupportedException("Setting the length of this stream is not supported.");
152-
}
145+
=> throw new NotSupportedException("Setting the length of this stream is not supported.");
153146

154147
/// <inheritdoc/>
155148
public override void Write(byte[] buffer, int offset, int count)
156-
{
157-
throw new NotSupportedException("Writing to this stream is not supported.");
158-
}
149+
=> throw new NotSupportedException("Writing to this stream is not supported.");
159150

160151
/// <inheritdoc/>
161152
protected override void Dispose(bool disposing)

SabreTools.Serialization/Extensions/PortableExecutable.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public static class PortableExecutable
1818
/// <param name="rva">Relative virtual address to convert</param>
1919
/// <param name="sections">Array of sections to check against</param>
2020
/// <returns>Physical address, 0 on error</returns>
21-
public static uint ConvertVirtualAddress(this uint rva, SectionHeader[]? sections)
21+
public static uint ConvertVirtualAddress(this uint rva, SectionHeader[] sections)
2222
{
2323
// If we have an invalid section table, we can't do anything
24-
if (sections == null || sections.Length == 0)
24+
if (sections.Length == 0)
2525
return 0;
2626

2727
// If the RVA is 0, we just return 0 because it's invalid
@@ -69,7 +69,7 @@ public static uint ConvertVirtualAddress(this uint rva, SectionHeader[]? section
6969
/// <param name="rva">Relative virtual address to convert</param>
7070
/// <param name="sections">Array of sections to check against</param>
7171
/// <returns>Section index, null on error</returns>
72-
public static int ContainingSectionIndex(this uint rva, SectionHeader[]? sections)
72+
public static int ContainingSectionIndex(this uint rva, SectionHeader[] sections)
7373
{
7474
// If we have an invalid section table, we can't do anything
7575
if (sections == null || sections.Length == 0)
@@ -1282,10 +1282,10 @@ public static PopupMenuItem ParsePopupMenuItem(this byte[] data, ref int offset)
12821282
/// <param name="data">Data to parse</param>
12831283
/// <param name="offset">Offset into the byte array</param>
12841284
/// <returns>A filled ResourceHeader on success, null on error</returns>
1285-
public static Data.Models.PortableExecutable.Resource.ResourceHeader ParseResourceHeader(this byte[] data, ref int offset)
1285+
public static Models.PortableExecutable.Resource.ResourceHeader ParseResourceHeader(this byte[] data, ref int offset)
12861286
{
12871287
// Read in the table
1288-
var obj = new Data.Models.PortableExecutable.Resource.ResourceHeader();
1288+
var obj = new Models.PortableExecutable.Resource.ResourceHeader();
12891289

12901290
obj.DataSize = data.ReadUInt32LittleEndian(ref offset);
12911291
obj.HeaderSize = data.ReadUInt32LittleEndian(ref offset);

SabreTools.Serialization/Extensions/TypeLengthValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class TypeLengthValue
1313
/// </summary>
1414
/// <param name="paddingLevel">Padding level of the item when formatting</param>
1515
/// <returns>String representing the TypeLengthValue, if possible</returns>
16-
public static string Format(this Data.Models.ASN1.TypeLengthValue tlv, int paddingLevel = 0)
16+
public static string Format(this Models.ASN1.TypeLengthValue tlv, int paddingLevel = 0)
1717
{
1818
// Create the left-padding string
1919
string padding = new(' ', paddingLevel);
@@ -38,7 +38,7 @@ public static string Format(this Data.Models.ASN1.TypeLengthValue tlv, int paddi
3838
if (tlv.Type.HasFlag(ASN1Type.V_ASN1_CONSTRUCTED))
3939
#endif
4040
{
41-
if (tlv.Value is not SabreTools.Data.Models.ASN1.TypeLengthValue[] valueAsObjectArray)
41+
if (tlv.Value is not Models.ASN1.TypeLengthValue[] valueAsObjectArray)
4242
{
4343
formatBuilder.Append(", Value: [INVALID DATA TYPE]");
4444
return formatBuilder.ToString();

SabreTools.Serialization/Readers/AACS.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public class AACS : BaseBinaryReader<MediaKeyBlock>
6565
private static Record? ParseRecord(Stream data)
6666
{
6767
// The first 4 bytes are the type and length
68-
RecordType type = (RecordType)data.ReadByteValue();
69-
uint recordLength = data.ReadUInt24LittleEndian();
70-
data.SeekIfPossible(-4, SeekOrigin.Current);
68+
RecordType type = (RecordType)data.PeekByteValue();
7169

7270
// Create a record based on the type
7371
return type switch

SabreTools.Serialization/Readers/PortableExecutable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public class PortableExecutable : BaseBinaryReader<Executable>
293293

294294
#endregion
295295

296+
// TODO: Pre-parse known resource types
296297
#region Resource Directory Table
297298

298299
// Should also be in a '.rsrc' section

SabreTools.Serialization/Wrappers/CFB.Extraction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.IO;
33
using System.Text;
44
using SabreTools.Data.Models.CFB;
5-
#if NETFRAMEWORK || NETSTANDARD
5+
#if NETFRAMEWORK || NETSTANDARD2_0
66
using SabreTools.IO.Extensions;
77
#endif
88

SabreTools.Serialization/Wrappers/CHD.Printing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void PrintInformation(StringBuilder builder)
3737
Print(builder, v5);
3838
break;
3939
default:
40-
builder.AppendLine("Unrecognized header type");
40+
builder.AppendLine($"Unrecognized header type: {Model}");
4141
builder.AppendLine();
4242
break;
4343
}

SabreTools.Serialization/Wrappers/IExtractable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SabreTools.Serialization.Wrappers
33
/// <summary>
44
/// Represents an item that is extractable
55
/// </summary>
6+
/// TODO: Investigate whether it's possible to do an ExtractToStream
67
public interface IExtractable
78
{
89
/// <summary>

SabreTools.Serialization/Wrappers/ISO9660.Printing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public void PrintInformation(StringBuilder builder)
3131
Print(builder, Model.DirectoryDescriptors, encoding);
3232
}
3333

34-
protected static void Print(StringBuilder builder, byte[]? systemArea)
34+
protected static void Print(StringBuilder builder, byte[] systemArea)
3535
{
36-
if (systemArea == null || systemArea.Length == 0)
36+
if (systemArea.Length == 0)
3737
builder.AppendLine(systemArea, " System Area");
3838
else if (Array.TrueForAll(systemArea, b => b == 0))
3939
builder.AppendLine("Zeroed", " System Area");

SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ public Dictionary<int, int> FileDirMap
9494

9595
return field;
9696
}
97-
98-
private set;
9997
} = null;
10098

10199
/// <summary>

0 commit comments

Comments
 (0)