mirror of
				https://github.com/sampletext32/ParkanPlayground.git
				synced 2025-10-31 21:39:45 +03:00 
			
		
		
		
	Fix nullability warnings by initializing fields in constructors
This commit is contained in:
		| @@ -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 | ||||
|          | ||||
|         /// <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]; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Initializes a new instance of the ExportDirectory class | ||||
|         /// </summary> | ||||
|         public ExportDirectory() | ||||
|         { | ||||
|             // Initialize string field to avoid nullability warning | ||||
|             DllName = string.Empty; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     /// <summary> | ||||
| @@ -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 | ||||
|          | ||||
|         /// <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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -15,6 +15,15 @@ namespace X86Disassembler.PE | ||||
|         public uint FirstThunk;          // RVA to first thunk | ||||
|          | ||||
|         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> | ||||
| @@ -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 | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Initializes a new instance of the ImportedFunction class | ||||
|         /// </summary> | ||||
|         public ImportedFunction() | ||||
|         { | ||||
|             // Initialize string field to avoid nullability warning | ||||
|             Name = string.Empty; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -45,6 +45,22 @@ namespace X86Disassembler.PE | ||||
|          | ||||
|         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> | ||||
|         /// Determines if the PE file is 64-bit based on the Magic value | ||||
|         /// </summary> | ||||
|   | ||||
| @@ -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!; | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
| @@ -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++) | ||||
|   | ||||
| @@ -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 | ||||
|                 { | ||||
|   | ||||
| @@ -22,6 +22,15 @@ namespace X86Disassembler.PE | ||||
|         public ushort NumberOfLinenumbers; // Number of line numbers | ||||
|         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> | ||||
|         /// Checks if the section contains code | ||||
|         /// </summary> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 bird_egop
					bird_egop