using WhiteMagic; using WhiteMagic.Native; using WhiteMagic.ThreadEnvironment; using Xunit; namespace WhiteMagicTest.ThreadEnvironment; public sealed class ManagedTebTests { [Fact] public void Read_current_thread_teb_fields_returns_plausible_values() { using var magic = Magic.OpenInProcess(); using var teb = new ManagedTeb(magic.Memory, (int)NativeMethods.GetCurrentThreadId()); Assert.NotEqual(IntPtr.Zero, teb.ReadTebAddress()); Assert.NotEqual(IntPtr.Zero, teb.ReadStackBase()); Assert.NotEqual(IntPtr.Zero, teb.ReadStackLimit()); // The stack grows down, so the base is above the limit on x86/x64. Assert.True((nuint)teb.ReadStackBase() > (nuint)teb.ReadStackLimit()); } }