0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 20:01:17 +03:00

Fix nullability warnings by initializing fields in constructors

This commit is contained in:
bird_egop 2025-04-12 18:05:31 +03:00
parent 79773b08aa
commit cf2d61915c
7 changed files with 86 additions and 3 deletions

View File

@ -26,5 +26,15 @@ namespace X86Disassembler.PE
public ushort e_oeminfo; // OEM information; e_oemid specific public ushort e_oeminfo; // OEM information; e_oemid specific
public ushort[] e_res2; // Reserved words public ushort[] e_res2; // Reserved words
public uint e_lfanew; // File address of new exe header public uint e_lfanew; // File address of new exe header
/// <summary>
/// Initializes a new instance of the DOSHeader class
/// </summary>
public DOSHeader()
{
// Initialize arrays to avoid nullability warnings
e_res = new ushort[4];
e_res2 = new ushort[10];
}
} }
} }

View File

@ -17,6 +17,15 @@ namespace X86Disassembler.PE
public uint AddressOfFunctions; // RVA of the export address table public uint AddressOfFunctions; // RVA of the export address table
public uint AddressOfNames; // RVA of the export names table public uint AddressOfNames; // RVA of the export names table
public uint AddressOfNameOrdinals; // RVA of the ordinal table public uint AddressOfNameOrdinals; // RVA of the ordinal table
/// <summary>
/// Initializes a new instance of the ExportDirectory class
/// </summary>
public ExportDirectory()
{
// Initialize string field to avoid nullability warning
DllName = string.Empty;
}
} }
/// <summary> /// <summary>
@ -29,5 +38,15 @@ namespace X86Disassembler.PE
public uint Address; // Function RVA public uint Address; // Function RVA
public bool IsForwarder; // True if this is a forwarder public bool IsForwarder; // True if this is a forwarder
public string ForwarderName; // Name of the forwarded function public string ForwarderName; // Name of the forwarded function
/// <summary>
/// Initializes a new instance of the ExportedFunction class
/// </summary>
public ExportedFunction()
{
// Initialize string fields to avoid nullability warnings
Name = string.Empty;
ForwarderName = string.Empty;
}
} }
} }

View File

@ -15,6 +15,15 @@ namespace X86Disassembler.PE
public uint FirstThunk; // RVA to first thunk public uint FirstThunk; // RVA to first thunk
public List<ImportedFunction> Functions { get; } = new List<ImportedFunction>(); public List<ImportedFunction> Functions { get; } = new List<ImportedFunction>();
/// <summary>
/// Initializes a new instance of the ImportDescriptor class
/// </summary>
public ImportDescriptor()
{
// Initialize string field to avoid nullability warning
DllName = string.Empty;
}
} }
/// <summary> /// <summary>
@ -27,5 +36,14 @@ namespace X86Disassembler.PE
public bool IsOrdinal; // True if imported by ordinal public bool IsOrdinal; // True if imported by ordinal
public ushort Ordinal; // Ordinal value (if imported by ordinal) public ushort Ordinal; // Ordinal value (if imported by ordinal)
public uint ThunkRVA; // RVA of the thunk for this function public uint ThunkRVA; // RVA of the thunk for this function
/// <summary>
/// Initializes a new instance of the ImportedFunction class
/// </summary>
public ImportedFunction()
{
// Initialize string field to avoid nullability warning
Name = string.Empty;
}
} }
} }

View File

@ -45,6 +45,22 @@ namespace X86Disassembler.PE
public DataDirectory[] DataDirectories; // Data directories public DataDirectory[] DataDirectories; // Data directories
/// <summary>
/// Initializes a new instance of the OptionalHeader class
/// </summary>
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];
}
/// <summary> /// <summary>
/// Determines if the PE file is 64-bit based on the Magic value /// Determines if the PE file is 64-bit based on the Magic value
/// </summary> /// </summary>

View File

@ -82,6 +82,17 @@ namespace X86Disassembler.PE
_fileHeaderParser = new FileHeaderParser(); _fileHeaderParser = new FileHeaderParser();
_optionalHeaderParser = new OptionalHeaderParser(); _optionalHeaderParser = new OptionalHeaderParser();
_sectionHeaderParser = new SectionHeaderParser(); _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!;
} }
/// <summary> /// <summary>
@ -113,7 +124,7 @@ namespace X86Disassembler.PE
// Parse Optional Header // Parse Optional Header
OptionalHeader = _optionalHeaderParser.Parse(reader); OptionalHeader = _optionalHeaderParser.Parse(reader);
Is64Bit = _optionalHeaderParser.Is64Bit(OptionalHeader); Is64Bit = OptionalHeader.Is64Bit();
// Parse Section Headers // Parse Section Headers
for (int i = 0; i < FileHeader.NumberOfSections; i++) for (int i = 0; i < FileHeader.NumberOfSections; i++)

View File

@ -140,9 +140,9 @@ namespace X86Disassembler.PE.Parsers
function.Address = functionRVA; function.Address = functionRVA;
// Check if this function has a name // 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 else
{ {

View File

@ -22,6 +22,15 @@ namespace X86Disassembler.PE
public ushort NumberOfLinenumbers; // Number of line numbers public ushort NumberOfLinenumbers; // Number of line numbers
public uint Characteristics; // Characteristics public uint Characteristics; // Characteristics
/// <summary>
/// Initializes a new instance of the SectionHeader class
/// </summary>
public SectionHeader()
{
// Initialize string field to avoid nullability warning
Name = string.Empty;
}
/// <summary> /// <summary>
/// Checks if the section contains code /// Checks if the section contains code
/// </summary> /// </summary>