Add layouts for some PE models

This commit is contained in:
Matt Nadareski
2024-04-23 16:42:29 -04:00
parent b8f67a8ab0
commit f60afd6368
9 changed files with 100 additions and 72 deletions

View File

@@ -1,12 +1,9 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// Type or Offset field entry is a WORD (2 bytes).
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class BaseRelocationTypeOffsetFieldEntry
{
/// <summary>

View File

@@ -1,9 +1,12 @@
namespace SabreTools.Models.PortableExecutable
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// One hint/name table suffices for the entire import section.
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class HintNameTableEntry
{
/// <summary>
@@ -11,13 +14,14 @@
/// with this value. If it fails, a binary search is performed on the DLL's
/// export name pointer table.
/// </summary>
public ushort Hint { get; set; }
public ushort Hint;
/// <summary>
/// An ASCII string that contains the name to import. This is the string that
/// must be matched to the public name in the DLL. This string is case sensitive
/// and terminated by a null byte.
/// </summary>
public string? Name { get; set; }
[MarshalAs(UnmanagedType.LPStr)]
public string? Name;
}
}

View File

@@ -1,62 +1,9 @@
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// Contains information about each item in a menu resource that does not open a menu
/// or a submenu. The structure definition provided here is for explanation only; it
/// is not present in any standard header file.
///
/// Contains information about the menu items in a menu resource that open a menu
/// or a submenu. The structure definition provided here is for explanation only;
/// it is not present in any standard header file.
/// Common base class for menu item types
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/menurc/normalmenuitem"/>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/menurc/popupmenuitem"/>
public sealed class MenuItem
{
#region NORMALMENUITEM
/// <summary>
/// The type of menu item.
/// </summary>
public MenuFlags NormalResInfo { get; set; }
/// <summary>
/// A null-terminated Unicode string that contains the text for this menu item.
/// There is no fixed limit on the size of this string.
/// </summary>
public string? NormalMenuText { get; set; }
#endregion
#region POPUPMENUITEM
/// <summary>
/// Describes the menu item.
/// </summary>
public MenuFlags PopupItemType { get; set; }
/// <summary>
/// Describes the menu item.
/// </summary>
public MenuFlags PopupState { get; set; }
/// <summary>
/// A numeric expression that identifies the menu item that is passed in the
/// WM_COMMAND message.
/// </summary>
public uint PopupID { get; set; }
/// <summary>
/// A set of bit flags that specify the type of menu item.
/// </summary>
public MenuFlags PopupResInfo { get; set; }
/// <summary>
/// A null-terminated Unicode string that contains the text for this menu item.
/// There is no fixed limit on the size of this string.
/// </summary>
public string? PopupMenuText { get; set; }
#endregion
}
public abstract class MenuItem { }
}

View File

@@ -35,8 +35,9 @@ namespace SabreTools.Models.PortableExecutable
/// <summary>
/// Null-terminated name of the PDB file. It can also contain full
/// or partial path to the file.
/// or partial path to the file.
/// </summary>
/// <remarks>Is this Unicode?</remarks>
[MarshalAs(UnmanagedType.LPStr)]
public string? PdbFileName;
}

View File

@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// Contains information about each item in a menu resource that does not open a menu
/// or a submenu. The structure definition provided here is for explanation only; it
/// is not present in any standard header file.
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/menurc/normalmenuitem"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class NormalMenuItem : MenuItem
{
/// <summary>
/// The type of menu item.
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public MenuFlags NormalResInfo;
/// <summary>
/// A null-terminated Unicode string that contains the text for this menu item.
/// There is no fixed limit on the size of this string.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string? NormalMenuText;
}
}

View File

@@ -0,0 +1,45 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// Contains information about the menu items in a menu resource that open a menu
/// or a submenu. The structure definition provided here is for explanation only;
/// it is not present in any standard header file.
/// </summary>
/// <see href="https://learn.microsoft.com/en-us/windows/win32/menurc/popupmenuitem"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class PopupMenuItem : MenuItem
{
/// <summary>
/// Describes the menu item.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public MenuFlags PopupItemType;
/// <summary>
/// Describes the menu item.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public MenuFlags PopupState;
/// <summary>
/// A numeric expression that identifies the menu item that is passed in the
/// WM_COMMAND message.
/// </summary>
public uint PopupID;
/// <summary>
/// A set of bit flags that specify the type of menu item.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public MenuFlags PopupResInfo;
/// <summary>
/// A null-terminated Unicode string that contains the text for this menu item.
/// There is no fixed limit on the size of this string.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string? PopupMenuText;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
{
@@ -7,28 +8,30 @@ namespace SabreTools.Models.PortableExecutable
/// or "DS" type which are emitted by Miscrosoft's link.exe from version 7 and above.
/// </summary>
/// <see href="http://www.godevtool.com/Other/pdb.htm"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class RSDSProgramDatabase
{
/// <summary>
/// "RSDS" signature
/// </summary>
public uint Signature { get; set; }
public uint Signature;
/// <summary>
/// 16-byte Globally Unique Identifier
/// </summary>
public Guid GUID { get; set; }
public Guid GUID;
/// <summary>
/// Ever-incrementing value, which is initially set to 1 and
/// incremented every time when a part of the PDB file is updated
/// without rewriting the whole file.
/// </summary>
public uint Age { get; set; }
public uint Age;
/// <summary>
/// zero terminated UTF8 path and file name
/// </summary>
public string? PathAndFileName { get; set; }
[MarshalAs(UnmanagedType.LPWStr)]
public string? PathAndFileName;
}
}

View File

@@ -1,4 +1,6 @@
namespace SabreTools.Models.PortableExecutable
using System.Runtime.InteropServices;
namespace SabreTools.Models.PortableExecutable
{
/// <summary>
/// Overlay data associated with SecuROM executables
@@ -15,7 +17,7 @@
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// <summary>s
/// Unknown (Entry count?)
/// </summary>
/// <remarks>
@@ -27,12 +29,14 @@
/// <summary>
/// Version, always 8 bytes?
/// </summary>
public string? Version { get; set; }
[MarshalAs(UnmanagedType.LPStr)]
public string? Version;
/// <summary>
/// Unknown (Build? Formatted as a string)
/// </summary>
public char[]? Build { get; set; }
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[]? Build;
/// <summary>
/// Unknown (0x14h), Variable number of bytes before entry table

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Models.PortableExecutable
/// Entry file name (null-terminated)
/// </summary>
/// <remarks>12 bytes long in the sample (all 3 entries) in 4.47.00.0039</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
[MarshalAs(UnmanagedType.LPStr)]
public string? FileName;
/// <summary>