diff --git a/X86Disassembler/PE/DOSHeader.cs b/X86Disassembler/PE/DOSHeader.cs
index d477807..ea30ee4 100644
--- a/X86Disassembler/PE/DOSHeader.cs
+++ b/X86Disassembler/PE/DOSHeader.cs
@@ -26,5 +26,15 @@ namespace X86Disassembler.PE
public ushort e_oeminfo; // OEM information; e_oemid specific
public ushort[] e_res2; // Reserved words
public uint e_lfanew; // File address of new exe header
+
+ ///
+ /// Initializes a new instance of the DOSHeader class
+ ///
+ public DOSHeader()
+ {
+ // Initialize arrays to avoid nullability warnings
+ e_res = new ushort[4];
+ e_res2 = new ushort[10];
+ }
}
}
diff --git a/X86Disassembler/PE/ExportDirectory.cs b/X86Disassembler/PE/ExportDirectory.cs
index 3b188e1..5ac097b 100644
--- a/X86Disassembler/PE/ExportDirectory.cs
+++ b/X86Disassembler/PE/ExportDirectory.cs
@@ -17,6 +17,15 @@ namespace X86Disassembler.PE
public uint AddressOfFunctions; // RVA of the export address table
public uint AddressOfNames; // RVA of the export names table
public uint AddressOfNameOrdinals; // RVA of the ordinal table
+
+ ///
+ /// Initializes a new instance of the ExportDirectory class
+ ///
+ public ExportDirectory()
+ {
+ // Initialize string field to avoid nullability warning
+ DllName = string.Empty;
+ }
}
///
@@ -29,5 +38,15 @@ namespace X86Disassembler.PE
public uint Address; // Function RVA
public bool IsForwarder; // True if this is a forwarder
public string ForwarderName; // Name of the forwarded function
+
+ ///
+ /// Initializes a new instance of the ExportedFunction class
+ ///
+ public ExportedFunction()
+ {
+ // Initialize string fields to avoid nullability warnings
+ Name = string.Empty;
+ ForwarderName = string.Empty;
+ }
}
}
diff --git a/X86Disassembler/PE/ImportDescriptor.cs b/X86Disassembler/PE/ImportDescriptor.cs
index c2d8ed3..5c8370a 100644
--- a/X86Disassembler/PE/ImportDescriptor.cs
+++ b/X86Disassembler/PE/ImportDescriptor.cs
@@ -15,6 +15,15 @@ namespace X86Disassembler.PE
public uint FirstThunk; // RVA to first thunk
public List Functions { get; } = new List();
+
+ ///
+ /// Initializes a new instance of the ImportDescriptor class
+ ///
+ public ImportDescriptor()
+ {
+ // Initialize string field to avoid nullability warning
+ DllName = string.Empty;
+ }
}
///
@@ -27,5 +36,14 @@ namespace X86Disassembler.PE
public bool IsOrdinal; // True if imported by ordinal
public ushort Ordinal; // Ordinal value (if imported by ordinal)
public uint ThunkRVA; // RVA of the thunk for this function
+
+ ///
+ /// Initializes a new instance of the ImportedFunction class
+ ///
+ public ImportedFunction()
+ {
+ // Initialize string field to avoid nullability warning
+ Name = string.Empty;
+ }
}
}
diff --git a/X86Disassembler/PE/OptionalHeader.cs b/X86Disassembler/PE/OptionalHeader.cs
index 2ac889b..42c7fd4 100644
--- a/X86Disassembler/PE/OptionalHeader.cs
+++ b/X86Disassembler/PE/OptionalHeader.cs
@@ -45,6 +45,22 @@ namespace X86Disassembler.PE
public DataDirectory[] DataDirectories; // Data directories
+ ///
+ /// Initializes a new instance of the OptionalHeader class
+ ///
+ public OptionalHeader()
+ {
+ // Initialize object fields to avoid nullability warnings
+ ImageBase = 0u; // Default to 32-bit value
+ SizeOfStackReserve = 0u;
+ SizeOfStackCommit = 0u;
+ SizeOfHeapReserve = 0u;
+ SizeOfHeapCommit = 0u;
+
+ // Initialize array to avoid nullability warning
+ DataDirectories = new DataDirectory[0];
+ }
+
///
/// Determines if the PE file is 64-bit based on the Magic value
///
diff --git a/X86Disassembler/PE/PEFormat.cs b/X86Disassembler/PE/PEFormat.cs
index bd41bfc..dbb8c62 100644
--- a/X86Disassembler/PE/PEFormat.cs
+++ b/X86Disassembler/PE/PEFormat.cs
@@ -82,6 +82,17 @@ namespace X86Disassembler.PE
_fileHeaderParser = new FileHeaderParser();
_optionalHeaderParser = new OptionalHeaderParser();
_sectionHeaderParser = new SectionHeaderParser();
+
+ // Initialize properties to avoid nullability warnings
+ DosHeader = new DOSHeader();
+ FileHeader = new FileHeader();
+ OptionalHeader = new OptionalHeader();
+ ExportDirectory = new ExportDirectory();
+
+ // These will be initialized during Parse()
+ _peUtility = null!;
+ _exportDirectoryParser = null!;
+ _importDescriptorParser = null!;
}
///
@@ -113,7 +124,7 @@ namespace X86Disassembler.PE
// Parse Optional Header
OptionalHeader = _optionalHeaderParser.Parse(reader);
- Is64Bit = _optionalHeaderParser.Is64Bit(OptionalHeader);
+ Is64Bit = OptionalHeader.Is64Bit();
// Parse Section Headers
for (int i = 0; i < FileHeader.NumberOfSections; i++)
diff --git a/X86Disassembler/PE/Parsers/ExportDirectoryParser.cs b/X86Disassembler/PE/Parsers/ExportDirectoryParser.cs
index 046b7b1..2e71f8b 100644
--- a/X86Disassembler/PE/Parsers/ExportDirectoryParser.cs
+++ b/X86Disassembler/PE/Parsers/ExportDirectoryParser.cs
@@ -140,9 +140,9 @@ namespace X86Disassembler.PE.Parsers
function.Address = functionRVA;
// Check if this function has a name
- if (ordinalToName.TryGetValue(i, out string name))
+ if (ordinalToName.TryGetValue(i, out string? name))
{
- function.Name = name;
+ function.Name = name ?? $"Ordinal_{function.Ordinal}";
}
else
{
diff --git a/X86Disassembler/PE/SectionHeader.cs b/X86Disassembler/PE/SectionHeader.cs
index a18c929..62cfb9a 100644
--- a/X86Disassembler/PE/SectionHeader.cs
+++ b/X86Disassembler/PE/SectionHeader.cs
@@ -22,6 +22,15 @@ namespace X86Disassembler.PE
public ushort NumberOfLinenumbers; // Number of line numbers
public uint Characteristics; // Characteristics
+ ///
+ /// Initializes a new instance of the SectionHeader class
+ ///
+ public SectionHeader()
+ {
+ // Initialize string field to avoid nullability warning
+ Name = string.Empty;
+ }
+
///
/// Checks if the section contains code
///