Try to make structs more marshalable

This commit is contained in:
Matt Nadareski
2021-04-01 11:09:20 -07:00
parent e0497e6fee
commit 80e71f43de
21 changed files with 218 additions and 169 deletions

View File

@@ -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();

View File

@@ -11,33 +11,37 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// DOS 1, 2, 3 .EXE header
/// </summary>
[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)
{

View File

@@ -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();

View File

@@ -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();

View File

@@ -11,47 +11,50 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// New .EXE header
/// </summary>
[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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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);

View File

@@ -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

View File

@@ -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();

View File

@@ -12,34 +12,37 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Relocation item
/// </summary>
/// 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();

View File

@@ -11,22 +11,24 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Relocation info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal class NewRlcInfo
{
/// <summary>
/// Number of relocation items that follow
/// </summary>
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();

View File

@@ -11,23 +11,25 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource table
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal class NewRsrc
{
/// <summary>
/// Alignment shift count for resources
/// </summary>
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);

View File

@@ -11,37 +11,39 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// New .EXE segment table entry
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal class NewSeg
{
/// <summary>
/// File sector of start of segment
/// </summary>
public ushort StartFileSector { get; private set; }
public ushort StartFileSector;
/// <summary>
/// Number of bytes in file
/// </summary>
public ushort BytesInFile { get; private set; }
public ushort BytesInFile;
/// <summary>
/// Attribute flags
/// </summary>
public ushort Flags { get; private set; }
public ushort Flags;
/// <summary>
/// Minimum allocation in bytes
/// </summary>
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();

View File

@@ -12,12 +12,15 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Segment data
/// </summary>
/// 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
/// <summary>
/// Number of iterations
/// </summary>
public ushort Iterations { get; private set; }
public ushort Iterations;
/// <summary>
/// Number of bytes
/// </summary>
public ushort TotalBytes { get; private set; }
public ushort TotalBytes;
/// <summary>
/// Iterated data bytes
/// </summary>
public char IteratedDataBytes { get; private set; }
public char IteratedDataBytes;
#endregion
@@ -44,13 +47,13 @@ namespace BurnOutSharp.ExecutableType.Microsoft
/// <summary>
/// Data bytes
/// </summary>
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();

View File

@@ -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);

View File

@@ -11,12 +11,14 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource name information block
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal class RsrcNameInfo
{
/*
@@ -29,36 +31,36 @@ namespace BurnOutSharp.ExecutableType.Microsoft
/// <summary>
/// File offset to resource data
/// </summary>
public ushort Offset { get; private set; }
public ushort Offset;
/// <summary>
/// Length of resource data
/// </summary>
public ushort Length { get; private set; }
public ushort Length;
/// <summary>
/// Resource flags
/// </summary>
public ushort Flags { get; private set; }
public ushort Flags;
/// <summary>
/// Resource name id
/// </summary>
public ushort NameID { get; private set; }
public ushort NameID;
/// <summary>
/// If loaded, then global handle
/// </summary>
public ushort Handle { get; private set; }
public ushort Handle;
/// <summary>
/// Initially zero. Number of times the handle for this resource has been given out
/// </summary>
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();

View File

@@ -11,27 +11,31 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource type or name string
/// </summary>
/// TODO: Fix this because SizeConst = 0 is not valid
[StructLayout(LayoutKind.Sequential)]
internal class RsrcString
{
/// <summary>
/// Number of bytes in string
/// </summary>
public byte Length { get; private set; }
public byte Length;
/// <summary>
/// Next of string
/// </summary>
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);

View File

@@ -11,21 +11,23 @@
*/
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource type information block
/// </summary>
[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();

View File

@@ -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();