From 80e71f43de02fb877ce61a3605b3c790610e8606 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 1 Apr 2021 11:09:20 -0700 Subject: [PATCH] Try to make structs more marshalable --- .../Microsoft/IMAGE_DATA_DIRECTORY.cs | 8 ++- .../Microsoft/IMAGE_DOS_HEADER.cs | 42 ++++++------ .../Microsoft/IMAGE_FILE_HEADER.cs | 18 ++--- .../Microsoft/IMAGE_OPTIONAL_HEADER.cs | 67 ++++++++++--------- .../Microsoft/IMAGE_OS2_HEADER.cs | 63 ++++++++--------- .../Microsoft/IMAGE_RESOURCE_DATA_ENTRY.cs | 12 ++-- .../Microsoft/IMAGE_RESOURCE_DIRECTORY.cs | 16 +++-- .../IMAGE_RESOURCE_DIRECTORY_ENTRY.cs | 8 ++- .../Microsoft/IMAGE_RESOURCE_DIR_STRING_U.cs | 8 ++- .../Microsoft/IMAGE_SECTION_HEADER.cs | 2 +- .../ExecutableType/Microsoft/NAMEINFO.cs | 16 +++-- .../ExecutableType/Microsoft/NewRlc.cs | 25 ++++--- .../ExecutableType/Microsoft/NewRlcInfo.cs | 6 +- .../ExecutableType/Microsoft/NewRsrc.cs | 8 ++- .../ExecutableType/Microsoft/NewSeg.cs | 12 ++-- .../ExecutableType/Microsoft/NewSegdata.cs | 13 ++-- .../ExecutableType/Microsoft/ResourceTable.cs | 15 +++-- .../ExecutableType/Microsoft/RsrcNameInfo.cs | 16 +++-- .../ExecutableType/Microsoft/RsrcString.cs | 10 ++- .../ExecutableType/Microsoft/RsrcTypeInfo.cs | 10 +-- .../ExecutableType/Microsoft/TYPEINFO.cs | 12 ++-- 21 files changed, 218 insertions(+), 169 deletions(-) diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DATA_DIRECTORY.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DATA_DIRECTORY.cs index e1eb001a..feb0a14b 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DATA_DIRECTORY.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DATA_DIRECTORY.cs @@ -11,17 +11,19 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_DATA_DIRECTORY { - public uint VirtualAddress { get; private set; } - public uint Size { get; private set; } + public uint VirtualAddress; + public uint Size; public static IMAGE_DATA_DIRECTORY Deserialize(Stream stream) { - IMAGE_DATA_DIRECTORY idd = new IMAGE_DATA_DIRECTORY(); + var idd = new IMAGE_DATA_DIRECTORY(); idd.VirtualAddress = stream.ReadUInt32(); idd.Size = stream.ReadUInt32(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DOS_HEADER.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DOS_HEADER.cs index e5bf6c17..cfe4cde0 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DOS_HEADER.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_DOS_HEADER.cs @@ -11,33 +11,37 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// DOS 1, 2, 3 .EXE header /// + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_DOS_HEADER { - public ushort Magic { get; private set; } // 00 Magic number - public ushort LastPageBytes { get; private set; } // 02 Bytes on last page of file - public ushort Pages { get; private set; } // 04 Pages in file - public ushort Relocations { get; private set; } // 06 Relocations - public ushort HeaderParagraphSize { get; private set; } // 08 Size of header in paragraphs - public ushort MinimumExtraParagraphs { get; private set; } // 0A Minimum extra paragraphs needed - public ushort MaximumExtraParagraphs { get; private set; } // 0C Maximum extra paragraphs needed - public ushort InitialSSValue { get; private set; } // 0E Initial (relative) SS value - public ushort InitialSPValue { get; private set; } // 10 Initial SP value - public ushort Checksum { get; private set; } // 12 Checksum - public ushort InitialIPValue { get; private set; } // 14 Initial IP value - public ushort InitialCSValue { get; private set; } // 16 Initial (relative) CS value - public ushort RelocationTableAddr { get; private set; } // 18 File address of relocation table - public ushort OverlayNumber { get; private set; } // 1A Overlay number - public ushort[] Reserved1 { get; private set; } // 1C Reserved words - public ushort OEMIdentifier { get; private set; } // 24 OEM identifier (for e_oeminfo) - public ushort OEMInformation { get; private set; } // 26 OEM information; e_oemid specific - public ushort[] Reserved2 { get; private set; } // 28 Reserved words - public int NewExeHeaderAddr { get; private set; } // 3C File address of new exe header + public ushort Magic; // 00 Magic number + public ushort LastPageBytes; // 02 Bytes on last page of file + public ushort Pages; // 04 Pages in file + public ushort Relocations; // 06 Relocations + public ushort HeaderParagraphSize; // 08 Size of header in paragraphs + public ushort MinimumExtraParagraphs; // 0A Minimum extra paragraphs needed + public ushort MaximumExtraParagraphs; // 0C Maximum extra paragraphs needed + public ushort InitialSSValue; // 0E Initial (relative) SS value + public ushort InitialSPValue; // 10 Initial SP value + public ushort Checksum; // 12 Checksum + public ushort InitialIPValue; // 14 Initial IP value + public ushort InitialCSValue; // 16 Initial (relative) CS value + public ushort RelocationTableAddr; // 18 File address of relocation table + public ushort OverlayNumber; // 1A Overlay number + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.ERES1WDS)] + public ushort[] Reserved1; // 1C Reserved words + public ushort OEMIdentifier; // 24 OEM identifier (for e_oeminfo) + public ushort OEMInformation; // 26 OEM information; e_oemid specific + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.ERES2WDS)] + public ushort[] Reserved2; // 28 Reserved words + public int NewExeHeaderAddr; // 3C File address of new exe header public static IMAGE_DOS_HEADER Deserialize(Stream stream) { diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_FILE_HEADER.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_FILE_HEADER.cs index ae452cb1..291e82b1 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_FILE_HEADER.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_FILE_HEADER.cs @@ -11,22 +11,24 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_FILE_HEADER { - public ushort Machine { get; private set; } - public ushort NumberOfSections { get; private set; } - public uint TimeDateStamp { get; private set; } - public uint PointerToSymbolTable { get; private set; } - public uint NumberOfSymbols { get; private set; } - public ushort SizeOfOptionalHeader { get; private set; } - public ushort Characteristics { get; private set; } + public ushort Machine; + public ushort NumberOfSections; + public uint TimeDateStamp; + public uint PointerToSymbolTable; + public uint NumberOfSymbols; + public ushort SizeOfOptionalHeader; + public ushort Characteristics; public static IMAGE_FILE_HEADER Deserialize(Stream stream) { - IMAGE_FILE_HEADER ifh = new IMAGE_FILE_HEADER(); + var ifh = new IMAGE_FILE_HEADER(); ifh.Machine = stream.ReadUInt16(); ifh.NumberOfSections = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OPTIONAL_HEADER.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OPTIONAL_HEADER.cs index 51a36f29..1e5d4662 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OPTIONAL_HEADER.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OPTIONAL_HEADER.cs @@ -11,51 +11,54 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_OPTIONAL_HEADER { // Standard fields - public ushort Magic { get; private set; } - public byte MajorLinkerVersion { get; private set; } - public byte MinorLinkerVersion { get; private set; } - public uint SizeOfCode { get; private set; } - public uint SizeOfInitializedData { get; private set; } - public uint SizeOfUninitializedData { get; private set; } - public uint AddressOfEntryPoint { get; private set; } - public uint BaseOfCode { get; private set; } - public uint BaseOfData { get; private set; } + public ushort Magic; + public byte MajorLinkerVersion; + public byte MinorLinkerVersion; + public uint SizeOfCode; + public uint SizeOfInitializedData; + public uint SizeOfUninitializedData; + public uint AddressOfEntryPoint; + public uint BaseOfCode; + public uint BaseOfData; // NT additional fields. - public uint ImageBase { get; private set; } - public uint SectionAlignment { get; private set; } - public uint FileAlignment { get; private set; } - public ushort MajorOperatingSystemVersion { get; private set; } - public ushort MinorOperatingSystemVersion { get; private set; } - public ushort MajorImageVersion { get; private set; } - public ushort MinorImageVersion { get; private set; } - public ushort MajorSubsystemVersion { get; private set; } - public ushort MinorSubsystemVersion { get; private set; } - public uint Reserved1 { get; private set; } - public uint SizeOfImage { get; private set; } - public uint SizeOfHeaders { get; private set; } - public uint CheckSum { get; private set; } - public ushort Subsystem { get; private set; } - public ushort DllCharacteristics { get; private set; } - public uint SizeOfStackReserve { get; private set; } - public uint SizeOfStackCommit { get; private set; } - public uint SizeOfHeapReserve { get; private set; } - public uint SizeOfHeapCommit { get; private set; } - public uint LoaderFlags { get; private set; } - public uint NumberOfRvaAndSizes { get; private set; } - public IMAGE_DATA_DIRECTORY[] DataDirectory { get; private set; } + public uint ImageBase; + public uint SectionAlignment; + public uint FileAlignment; + public ushort MajorOperatingSystemVersion; + public ushort MinorOperatingSystemVersion; + public ushort MajorImageVersion; + public ushort MinorImageVersion; + public ushort MajorSubsystemVersion; + public ushort MinorSubsystemVersion; + public uint Reserved1; + public uint SizeOfImage; + public uint SizeOfHeaders; + public uint CheckSum; + public ushort Subsystem; + public ushort DllCharacteristics; + public uint SizeOfStackReserve; + public uint SizeOfStackCommit; + public uint SizeOfHeapReserve; + public uint SizeOfHeapCommit; + public uint LoaderFlags; + public uint NumberOfRvaAndSizes; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES)] + public IMAGE_DATA_DIRECTORY[] DataDirectory; public static IMAGE_OPTIONAL_HEADER Deserialize(Stream stream) { - IMAGE_OPTIONAL_HEADER ioh = new IMAGE_OPTIONAL_HEADER(); + var ioh = new IMAGE_OPTIONAL_HEADER(); ioh.Magic = stream.ReadUInt16(); ioh.MajorLinkerVersion = stream.ReadByteValue(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OS2_HEADER.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OS2_HEADER.cs index 08a09b08..7344407f 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OS2_HEADER.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_OS2_HEADER.cs @@ -11,47 +11,50 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// New .EXE header /// + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_OS2_HEADER { - public ushort Magic { get; private set; } // 00 Magic number NE_MAGIC - public byte LinkerVersion { get; private set; } // 02 Linker Version number - public byte LinkerRevision { get; private set; } // 03 Linker Revision number - public ushort EntryTableOffset { get; private set; } // 04 Offset of Entry Table - public ushort EntryTableSize { get; private set; } // 06 Number of bytes in Entry Table - public uint CrcChecksum { get; private set; } // 08 Checksum of whole file - public ushort Flags { get; private set; } // 0C Flag word - public ushort Autodata { get; private set; } // 0E Automatic data segment number - public ushort InitialHeapAlloc { get; private set; } // 10 Initial heap allocation - public ushort InitialStackAlloc { get; private set; } // 12 Initial stack allocation - public uint InitialCSIPSetting { get; private set; } // 14 Initial CS:IP setting - public uint InitialSSSPSetting { get; private set; } // 18 Initial SS:SP setting - public ushort FileSegmentCount { get; private set; } // 1C Count of file segments - public ushort ModuleReferenceTableSize { get; private set; } // 1E Entries in Module Reference Table - public ushort NonResidentNameTableSize { get; private set; } // 20 Size of non-resident name table - public ushort SegmentTableOffset { get; private set; } // 22 Offset of Segment Table - public ushort ResourceTableOffset { get; private set; } // 24 Offset of Resource Table - public ushort ResidentNameTableOffset { get; private set; } // 26 Offset of resident name table - public ushort ModuleReferenceTableOffset { get; private set; } // 28 Offset of Module Reference Table - public ushort ImportedNamesTableOffset { get; private set; } // 2A Offset of Imported Names Table - public uint NonResidentNamesTableOffset { get; private set; } // 2C Offset of Non-resident Names Table - public ushort MovableEntriesCount { get; private set; } // 30 Count of movable entries - public ushort SegmentAlignmentShiftCount { get; private set; } // 32 Segment alignment shift count - public ushort ResourceEntriesCount { get; private set; } // 34 Count of resource entries - public byte TargetOperatingSystem { get; private set; } // 36 Target operating system - public byte AdditionalFlags { get; private set; } // 37 Additional flags - public ushort[] Reserved { get; private set; } // 38 3 reserved words - public byte WindowsSDKRevision { get; private set; } // 3E Windows SDK revison number - public byte WindowsSDKVersion { get; private set; } // 3F Windows SDK version number + public ushort Magic; // 00 Magic number NE_MAGIC + public byte LinkerVersion; // 02 Linker Version number + public byte LinkerRevision; // 03 Linker Revision number + public ushort EntryTableOffset; // 04 Offset of Entry Table + public ushort EntryTableSize; // 06 Number of bytes in Entry Table + public uint CrcChecksum; // 08 Checksum of whole file + public ushort Flags; // 0C Flag word + public ushort Autodata; // 0E Automatic data segment number + public ushort InitialHeapAlloc; // 10 Initial heap allocation + public ushort InitialStackAlloc; // 12 Initial stack allocation + public uint InitialCSIPSetting; // 14 Initial CS:IP setting + public uint InitialSSSPSetting; // 18 Initial SS:SP setting + public ushort FileSegmentCount; // 1C Count of file segments + public ushort ModuleReferenceTableSize; // 1E Entries in Module Reference Table + public ushort NonResidentNameTableSize; // 20 Size of non-resident name table + public ushort SegmentTableOffset; // 22 Offset of Segment Table + public ushort ResourceTableOffset; // 24 Offset of Resource Table + public ushort ResidentNameTableOffset; // 26 Offset of resident name table + public ushort ModuleReferenceTableOffset; // 28 Offset of Module Reference Table + public ushort ImportedNamesTableOffset; // 2A Offset of Imported Names Table + public uint NonResidentNamesTableOffset; // 2C Offset of Non-resident Names Table + public ushort MovableEntriesCount; // 30 Count of movable entries + public ushort SegmentAlignmentShiftCount; // 32 Segment alignment shift count + public ushort ResourceEntriesCount; // 34 Count of resource entries + public byte TargetOperatingSystem; // 36 Target operating system + public byte AdditionalFlags; // 37 Additional flags + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.NERESWORDS)] + public ushort[] Reserved; // 38 3 reserved words + public byte WindowsSDKRevision; // 3E Windows SDK revison number + public byte WindowsSDKVersion; // 3F Windows SDK version number public static IMAGE_OS2_HEADER Deserialize(Stream stream) { - IMAGE_OS2_HEADER ioh = new IMAGE_OS2_HEADER(); + var ioh = new IMAGE_OS2_HEADER(); ioh.Magic = stream.ReadUInt16(); ioh.LinkerVersion = stream.ReadByteValue(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DATA_ENTRY.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DATA_ENTRY.cs index bed0ad39..d99e28d2 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DATA_ENTRY.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DATA_ENTRY.cs @@ -11,19 +11,21 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_RESOURCE_DATA_ENTRY { - public uint OffsetToData { get; private set; } - public uint Size { get; private set; } - public uint CodePage { get; private set; } - public uint Reserved { get; private set; } + public uint OffsetToData; + public uint Size; + public uint CodePage; + public uint Reserved; public static IMAGE_RESOURCE_DATA_ENTRY Deserialize(Stream stream) { - IMAGE_RESOURCE_DATA_ENTRY irde = new IMAGE_RESOURCE_DATA_ENTRY(); + var irde = new IMAGE_RESOURCE_DATA_ENTRY(); irde.OffsetToData = stream.ReadUInt32(); irde.Size = stream.ReadUInt32(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY.cs index 81d9fc57..2acd18ce 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY.cs @@ -11,21 +11,23 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_RESOURCE_DIRECTORY { - public uint Characteristics { get; private set; } - public uint TimeDateStamp { get; private set; } - public ushort MajorVersion { get; private set; } - public ushort MinorVersion { get; private set; } - public ushort NumberOfNamedEntries { get; private set; } - public ushort NumberOfIdEntries { get; private set; } + public uint Characteristics; + public uint TimeDateStamp; + public ushort MajorVersion; + public ushort MinorVersion; + public ushort NumberOfNamedEntries; + public ushort NumberOfIdEntries; public static IMAGE_RESOURCE_DIRECTORY Deserialize(Stream stream) { - IMAGE_RESOURCE_DIRECTORY ird = new IMAGE_RESOURCE_DIRECTORY(); + var ird = new IMAGE_RESOURCE_DIRECTORY(); ird.Characteristics = stream.ReadUInt32(); ird.TimeDateStamp = stream.ReadUInt32(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY_ENTRY.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY_ENTRY.cs index e10f8d69..ebbb16b5 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY_ENTRY.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIRECTORY_ENTRY.cs @@ -11,17 +11,19 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_RESOURCE_DIRECTORY_ENTRY { - public uint Name { get; private set; } - public uint OffsetToData { get; private set; } + public uint Name; + public uint OffsetToData; public static IMAGE_RESOURCE_DIRECTORY_ENTRY Deserialize(Stream stream) { - IMAGE_RESOURCE_DIRECTORY_ENTRY irde = new IMAGE_RESOURCE_DIRECTORY_ENTRY(); + var irde = new IMAGE_RESOURCE_DIRECTORY_ENTRY(); irde.Name = stream.ReadUInt32(); irde.OffsetToData = stream.ReadUInt32(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIR_STRING_U.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIR_STRING_U.cs index 78674376..a551395e 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIR_STRING_U.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_RESOURCE_DIR_STRING_U.cs @@ -11,17 +11,19 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class IMAGE_RESOURCE_DIR_STRING_U { - public ushort Length { get; private set; } - public char[] NameString { get; private set; } + public ushort Length; + public char[] NameString; public static IMAGE_RESOURCE_DIR_STRING_U Deserialize(Stream stream) { - IMAGE_RESOURCE_DIR_STRING_U irdsu = new IMAGE_RESOURCE_DIR_STRING_U(); + var irdsu = new IMAGE_RESOURCE_DIR_STRING_U(); irdsu.Length = stream.ReadUInt16(); irdsu.NameString = stream.ReadChars(irdsu.Length); diff --git a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_SECTION_HEADER.cs b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_SECTION_HEADER.cs index 2f523eec..ad57ddb7 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/IMAGE_SECTION_HEADER.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/IMAGE_SECTION_HEADER.cs @@ -18,7 +18,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft [StructLayout(LayoutKind.Sequential)] internal class IMAGE_SECTION_HEADER { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.IMAGE_SIZEOF_SHORT_NAME)] public byte[] Name; // Misc diff --git a/BurnOutSharp/ExecutableType/Microsoft/NAMEINFO.cs b/BurnOutSharp/ExecutableType/Microsoft/NAMEINFO.cs index da627132..3fd1dc7f 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NAMEINFO.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NAMEINFO.cs @@ -11,21 +11,23 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class NAMEINFO { - public ushort Offset { get; private set; } - public ushort Length { get; private set; } - public ushort Flags { get; private set; } - public ushort ID { get; private set; } - public ushort Handle { get; private set; } - public ushort Usage { get; private set; } + public ushort Offset; + public ushort Length; + public ushort Flags; + public ushort ID; + public ushort Handle; + public ushort Usage; public static NAMEINFO Deserialize(Stream stream) { - NAMEINFO ni = new NAMEINFO(); + var ni = new NAMEINFO(); ni.Offset = stream.ReadUInt16(); ni.Length = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/NewRlc.cs b/BurnOutSharp/ExecutableType/Microsoft/NewRlc.cs index 1ac33395..11a3817f 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NewRlc.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NewRlc.cs @@ -12,34 +12,37 @@ using System; using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Relocation item /// + /// TODO: Fix this because Marshal will not work since it's not a direct read + [StructLayout(LayoutKind.Sequential)] internal class NewRlc { - public char SourceType { get; private set; } // Source type - public char Flags { get; private set; } // Flag byte - public ushort SourceOffset { get; private set; } // Source offset + public char SourceType; // Source type + public char Flags; // Flag byte + public ushort SourceOffset; // Source offset // nr_intref - Internal Reference - public char TargetSegmentNumber { get; private set; } // Target segment number - public char Reserved1 { get; private set; } // Reserved - public ushort TargetEntryTableOffset { get; private set; } // Target Entry Table offset + public char TargetSegmentNumber; // Target segment number + public char Reserved1; // Reserved + public ushort TargetEntryTableOffset; // Target Entry Table offset // nr_import - Import - public ushort ModuleReferenceTableIndex { get; private set; } // Index into Module Reference Table - public ushort ProcedureOffset { get; private set; } // Procedure ordinal or name offset + public ushort ModuleReferenceTableIndex; // Index into Module Reference Table + public ushort ProcedureOffset; // Procedure ordinal or name offset // nr_osfix - Operating system fixup - public ushort OperatingSystemFixupType { get; private set; } // OSFIXUP type - public ushort Reserved2 { get; private set; } // Reserved + public ushort OperatingSystemFixupType; // OSFIXUP type + public ushort Reserved2; // Reserved public static NewRlc Deserialize(Stream stream) { - NewRlc nr = new NewRlc(); + var nr = new NewRlc(); nr.SourceType = stream.ReadChar(); nr.Flags = stream.ReadChar(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/NewRlcInfo.cs b/BurnOutSharp/ExecutableType/Microsoft/NewRlcInfo.cs index f1a09474..80b37b80 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NewRlcInfo.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NewRlcInfo.cs @@ -11,22 +11,24 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Relocation info /// + [StructLayout(LayoutKind.Sequential)] internal class NewRlcInfo { /// /// Number of relocation items that follow /// - public ushort RelocationItemCount { get; private set; } + public ushort RelocationItemCount; public static NewRlcInfo Deserialize(Stream stream) { - NewRlcInfo nri = new NewRlcInfo(); + var nri = new NewRlcInfo(); nri.RelocationItemCount = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/NewRsrc.cs b/BurnOutSharp/ExecutableType/Microsoft/NewRsrc.cs index 9fda78f0..06863fe6 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NewRsrc.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NewRsrc.cs @@ -11,23 +11,25 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Resource table /// + [StructLayout(LayoutKind.Sequential)] internal class NewRsrc { /// /// Alignment shift count for resources /// - public ushort AlignmentShiftCount { get; private set; } - public RsrcTypeInfo TypeInfo { get; private set; } + public ushort AlignmentShiftCount; + public RsrcTypeInfo TypeInfo; public static NewRsrc Deserialize(Stream stream) { - NewRsrc nr = new NewRsrc(); + var nr = new NewRsrc(); nr.AlignmentShiftCount = stream.ReadUInt16(); nr.TypeInfo = RsrcTypeInfo.Deserialize(stream); diff --git a/BurnOutSharp/ExecutableType/Microsoft/NewSeg.cs b/BurnOutSharp/ExecutableType/Microsoft/NewSeg.cs index 3d10a2c3..f5fb04fc 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NewSeg.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NewSeg.cs @@ -11,37 +11,39 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// New .EXE segment table entry /// + [StructLayout(LayoutKind.Sequential)] internal class NewSeg { /// /// File sector of start of segment /// - public ushort StartFileSector { get; private set; } + public ushort StartFileSector; /// /// Number of bytes in file /// - public ushort BytesInFile { get; private set; } + public ushort BytesInFile; /// /// Attribute flags /// - public ushort Flags { get; private set; } + public ushort Flags; /// /// Minimum allocation in bytes /// - public ushort MinimumAllocation { get; private set; } + public ushort MinimumAllocation; public static NewSeg Deserialize(Stream stream) { - NewSeg ns = new NewSeg(); + var ns = new NewSeg(); ns.StartFileSector = stream.ReadUInt16(); ns.BytesInFile = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/NewSegdata.cs b/BurnOutSharp/ExecutableType/Microsoft/NewSegdata.cs index a39d86a7..3b94811d 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NewSegdata.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NewSegdata.cs @@ -12,12 +12,15 @@ using System; using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Segment data /// + /// TODO: Fix this because Marshal will not work since it's not a direct read + [StructLayout(LayoutKind.Sequential)] internal class NewSegdata { #region ns_iter @@ -25,17 +28,17 @@ namespace BurnOutSharp.ExecutableType.Microsoft /// /// Number of iterations /// - public ushort Iterations { get; private set; } + public ushort Iterations; /// /// Number of bytes /// - public ushort TotalBytes { get; private set; } + public ushort TotalBytes; /// /// Iterated data bytes /// - public char IteratedDataBytes { get; private set; } + public char IteratedDataBytes; #endregion @@ -44,13 +47,13 @@ namespace BurnOutSharp.ExecutableType.Microsoft /// /// Data bytes /// - public char DataBytes { get; private set; } + public char DataBytes; #endregion public static NewSegdata Deserialize(Stream stream) { - NewSegdata nsd = new NewSegdata(); + var nsd = new NewSegdata(); nsd.Iterations = stream.ReadUInt16(); nsd.TotalBytes = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/ResourceTable.cs b/BurnOutSharp/ExecutableType/Microsoft/ResourceTable.cs index e434693c..314c340e 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/ResourceTable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/ResourceTable.cs @@ -11,20 +11,23 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class ResourceTable { - public ushort rscAlignShift { get; private set; } - public TYPEINFO TypeInfo { get; private set; } - public ushort rscEndTypes { get; private set; } - public sbyte[][] rscResourceNames { get; private set; } - public byte rscEndNames { get; private set; } + public ushort rscAlignShift; + public TYPEINFO TypeInfo; + public ushort rscEndTypes; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)] + public sbyte[][] rscResourceNames; + public byte rscEndNames; public static ResourceTable Deserialize(Stream stream) { - ResourceTable rt = new ResourceTable(); + var rt = new ResourceTable(); rt.rscAlignShift = stream.ReadUInt16(); rt.TypeInfo = TYPEINFO.Deserialize(stream); diff --git a/BurnOutSharp/ExecutableType/Microsoft/RsrcNameInfo.cs b/BurnOutSharp/ExecutableType/Microsoft/RsrcNameInfo.cs index bb2a5d74..8edca310 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/RsrcNameInfo.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/RsrcNameInfo.cs @@ -11,12 +11,14 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Resource name information block /// + [StructLayout(LayoutKind.Sequential)] internal class RsrcNameInfo { /* @@ -29,36 +31,36 @@ namespace BurnOutSharp.ExecutableType.Microsoft /// /// File offset to resource data /// - public ushort Offset { get; private set; } + public ushort Offset; /// /// Length of resource data /// - public ushort Length { get; private set; } + public ushort Length; /// /// Resource flags /// - public ushort Flags { get; private set; } + public ushort Flags; /// /// Resource name id /// - public ushort NameID { get; private set; } + public ushort NameID; /// /// If loaded, then global handle /// - public ushort Handle { get; private set; } + public ushort Handle; /// /// Initially zero. Number of times the handle for this resource has been given out /// - public ushort UsageCount { get; private set; } + public ushort UsageCount; public static RsrcNameInfo Deserialize(Stream stream) { - RsrcNameInfo rni = new RsrcNameInfo(); + var rni = new RsrcNameInfo(); rni.Offset = stream.ReadUInt16(); rni.Length = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/RsrcString.cs b/BurnOutSharp/ExecutableType/Microsoft/RsrcString.cs index 4a00be0e..96e12cfd 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/RsrcString.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/RsrcString.cs @@ -11,27 +11,31 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Resource type or name string /// + /// TODO: Fix this because SizeConst = 0 is not valid + [StructLayout(LayoutKind.Sequential)] internal class RsrcString { /// /// Number of bytes in string /// - public byte Length { get; private set; } + public byte Length; /// /// Next of string /// - public char[] Text { get; private set; } + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)] + public char[] Text; public static RsrcString Deserialize(Stream stream) { - RsrcString rs = new RsrcString(); + var rs = new RsrcString(); rs.Length = stream.ReadByteValue(); rs.Text = stream.ReadChars(rs.Length); diff --git a/BurnOutSharp/ExecutableType/Microsoft/RsrcTypeInfo.cs b/BurnOutSharp/ExecutableType/Microsoft/RsrcTypeInfo.cs index 5cf25743..720728dd 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/RsrcTypeInfo.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/RsrcTypeInfo.cs @@ -11,21 +11,23 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { /// /// Resource type information block /// + [StructLayout(LayoutKind.Sequential)] internal class RsrcTypeInfo { - public ushort ID { get; private set; } - public ushort rt_nres { get; private set; } - public uint rt_proc { get; private set; } + public ushort ID; + public ushort rt_nres; + public uint rt_proc; public static RsrcTypeInfo Deserialize(Stream stream) { - RsrcTypeInfo rti = new RsrcTypeInfo(); + var rti = new RsrcTypeInfo(); rti.ID = stream.ReadUInt16(); rti.rt_nres = stream.ReadUInt16(); diff --git a/BurnOutSharp/ExecutableType/Microsoft/TYPEINFO.cs b/BurnOutSharp/ExecutableType/Microsoft/TYPEINFO.cs index 64b99ace..0f1bd736 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/TYPEINFO.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/TYPEINFO.cs @@ -11,19 +11,21 @@ */ using System.IO; +using System.Runtime.InteropServices; namespace BurnOutSharp.ExecutableType.Microsoft { + [StructLayout(LayoutKind.Sequential)] internal class TYPEINFO { - public ushort TypeID { get; private set; } - public ushort ResourceCount { get; private set; } - public uint Reserved { get; private set; } - public NAMEINFO NameInfo { get; private set; } + public ushort TypeID; + public ushort ResourceCount; + public uint Reserved; + public NAMEINFO NameInfo; public static TYPEINFO Deserialize(Stream stream) { - TYPEINFO ti = new TYPEINFO(); + var ti = new TYPEINFO(); ti.TypeID = stream.ReadUInt16(); ti.ResourceCount = stream.ReadUInt16();