using System.Runtime.InteropServices;
namespace WhiteMagic.Native;
///
/// The x87 and MMX state inside a 32-bit thread context.
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct FloatingSaveArea32
{
/// The x87 FPU control word.
public uint ControlWord;
/// The x87 FPU status word.
public uint StatusWord;
/// The x87 FPU tag word.
public uint TagWord;
/// The offset of the instruction that caused the last FPU exception.
public uint ErrorOffset;
/// The selector of the instruction that caused the last FPU exception.
public uint ErrorSelector;
/// The offset of the operand that caused the last FPU exception.
public uint DataOffset;
/// The selector of the operand that caused the last FPU exception.
public uint DataSelector;
/// The 80-byte register area.
public fixed byte RegisterArea[80];
/// The CR0 numeric-processor-extension state.
public uint Cr0NpxState;
}
///
/// A 32-bit (x86/WOW64) thread context. Use it with
/// Wow64GetThreadContext and Wow64SetThreadContext to inspect a 32-bit thread.
/// The total size is 716 bytes.
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Context32
{
/// Selects which parts of the context are valid. See .
public uint ContextFlags;
/// Debug register 0.
public uint Dr0;
/// Debug register 1.
public uint Dr1;
/// Debug register 2.
public uint Dr2;
/// Debug register 3.
public uint Dr3;
/// Debug register 6.
public uint Dr6;
/// Debug register 7.
public uint Dr7;
/// The floating-point state.
public FloatingSaveArea32 FloatSave;
/// The GS segment.
public uint SegGs;
/// The FS segment.
public uint SegFs;
/// The ES segment.
public uint SegEs;
/// The DS segment.
public uint SegDs;
/// The EDI register.
public uint Edi;
/// The ESI register.
public uint Esi;
/// The EBX register.
public uint Ebx;
/// The EDX register.
public uint Edx;
/// The ECX register.
public uint Ecx;
/// The EAX register.
public uint Eax;
/// The base (frame) pointer.
public uint Ebp;
/// The instruction pointer.
public uint Eip;
/// The CS segment.
public uint SegCs;
/// The flags register.
public uint EFlags;
/// The stack pointer.
public uint Esp;
/// The SS segment.
public uint SegSs;
/// The extended (processor-specific) registers. The size is 512 bytes.
public fixed byte ExtendedRegisters[512];
}
///
/// A 64-bit (AMD64) thread context. Use it with the native
/// GetThreadContext and SetThreadContext from a 64-bit process.
/// The structure needs 16-byte alignment. The total size is 1232 bytes.
///
[StructLayout(LayoutKind.Sequential, Pack = 16)]
public unsafe struct Context64
{
/// Home storage for a register parameter.
public ulong P1Home;
/// Home storage for a register parameter.
public ulong P2Home;
/// Home storage for a register parameter.
public ulong P3Home;
/// Home storage for a register parameter.
public ulong P4Home;
/// Home storage for a register parameter.
public ulong P5Home;
/// Home storage for a register parameter.
public ulong P6Home;
/// Selects which parts of the context are valid. See .
public uint ContextFlags;
/// The MXCSR register.
public uint MxCsr;
/// The CS segment.
public ushort SegCs;
/// The DS segment.
public ushort SegDs;
/// The ES segment.
public ushort SegEs;
/// The FS segment.
public ushort SegFs;
/// The GS segment.
public ushort SegGs;
/// The SS segment.
public ushort SegSs;
/// The flags register.
public uint EFlags;
/// Debug register 0.
public ulong Dr0;
/// Debug register 1.
public ulong Dr1;
/// Debug register 2.
public ulong Dr2;
/// Debug register 3.
public ulong Dr3;
/// Debug register 6.
public ulong Dr6;
/// Debug register 7.
public ulong Dr7;
/// The RAX register.
public ulong Rax;
/// The RCX register.
public ulong Rcx;
/// The RDX register.
public ulong Rdx;
/// The RBX register.
public ulong Rbx;
/// The stack pointer.
public ulong Rsp;
/// The base (frame) pointer.
public ulong Rbp;
/// The RSI register.
public ulong Rsi;
/// The RDI register.
public ulong Rdi;
/// The R8 register.
public ulong R8;
/// The R9 register.
public ulong R9;
/// The R10 register.
public ulong R10;
/// The R11 register.
public ulong R11;
/// The R12 register.
public ulong R12;
/// The R13 register.
public ulong R13;
/// The R14 register.
public ulong R14;
/// The R15 register.
public ulong R15;
/// The instruction pointer.
public ulong Rip;
/// The XMM save area. The size is 512 bytes.
public fixed byte FltSave[512];
/// The vector registers (26 entries of 16 bytes, stored as 52 entries of 8 bytes).
public fixed ulong VectorRegister[52];
/// The vector control register.
public ulong VectorControl;
/// The debug-control MSR.
public ulong DebugControl;
/// The target RIP of the last branch.
public ulong LastBranchToRip;
/// The source RIP of the last branch.
public ulong LastBranchFromRip;
/// The target RIP of the last exception.
public ulong LastExceptionToRip;
/// The source RIP of the last exception.
public ulong LastExceptionFromRip;
}