Beispiel #1
0
        private void EnumThreads()
        {
            var threads = SystemInformation.EnumThreads(_process.Id);

            _threads = new List <ThreadStack>(threads.Length);

            foreach (var thread in threads)
            {
                using (var hThread = _driver.OpenThreadHandle(ThreadAccessMask.QueryInformation, thread.Id)) {
                    if (hThread == null)
                    {
                        continue;
                    }

                    var nt = NativeThread.FromHandle(hThread.DangerousGetHandle(), false);
                    nt.GetStackLimits(_hProcess, out var stackBase, out var stackLimit);
                    if (stackBase > 0)
                    {
                        _threads.Add(new ThreadStack {
                            Base = stackBase, Limit = stackLimit, ThreadId = thread.Id, ProcessId = thread.ProcessId
                        });
                    }
                }
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     foreach (var thread in SystemInformation.EnumThreads())
     {
         Console.Write($"TID={thread.Id}, PID={thread.ProcessId}");
         var nt = NativeThread.TryOpen(ThreadAccessMask.QueryInformation, thread.Id);
         if (nt != null)
         {
             nt.GetStackLimits(out var min, out var max);
             Console.Write($" Stack: 0x{min:X} 0x{max:X}");
         }
         Console.WriteLine();
     }
 }