/// <summary> /// Gets the TLS address of the specified thread and slot index. /// </summary> /// <param name="threadHandle"></param> /// <param name="slotIndex"></param> /// <returns></returns> public uint GetTlsAddress(IntPtr threadHandle, int slotIndex = 0) { Kernel32.SuspendThread(threadHandle); ThreadContext context = Kernel32.GetThreadContext(threadHandle); Kernel32.ResumeThread(threadHandle); LdtEntry ldt = Kernel32.GetThreadSelectorEntry(threadHandle, context.SegFs); uint tlsArrayPtr = ldt.BaseAddress + 0x2C; uint tlsArrayAddress = Memory.ReadUInt32(tlsArrayPtr); return(Memory.ReadUInt32(tlsArrayAddress + slotIndex * sizeof(uint))); }
public static extern bool GetThreadSelectorEntry(SafeMemoryHandle hThread, uint dwSelector, out LdtEntry lpSelectorEntry);
public static extern bool GetThreadSelectorEntry(SafeMemoryHandle hThread, int dwSelector, out LdtEntry lpSelectorEntry);
private static extern bool UnmanagedGetThreadSelectorEntry( IntPtr hThread, uint dwSelector, out LdtEntry lpSelectorEntry );