Example #1
0
 public thread(UInt32 id, UInt32 thID, threadtimes tht)
 {
     dwOwnerProcID = id;
     thread_times = tht;
     dwThreadID = thID;
     if (thID == 0)
         System.Diagnostics.Debugger.Break();
 }
Example #2
0
        public thread FromByte(byte[] buf, ref int offset)
        {
            dwOwnerProcID = BitConverter.ToUInt32(buf, offset); //4 bytes
            offset += sizeof(System.UInt32);

            thread_times = new threadtimes(buf, ref offset);
            
            dwThreadID = BitConverter.ToUInt32(buf, offset);
            offset += sizeof(System.UInt32);

            return this;
        }
Example #3
0
        /// Gets the list of currently running threads
        public static Dictionary<uint, thread> GetThreadList()
        {
            Dictionary<uint, thread> process_list = new Dictionary<uint, thread>();
            //CosmicPowers we_are_powerful;
            UInt32 old_permissions = SetProcPermissions(0xffffffff);
            IntPtr snapshot = CreateToolhelp32Snapshot(SnapshotFlags.Thread | SnapshotFlags.NoHeaps, 0);
            if ((int)snapshot != -1)
            {
                THREADENTRY32 te = new THREADENTRY32();
                te.dwSize = (uint)Marshal.SizeOf(te);
                Int32 bRes = Thread32First(snapshot, ref te);
                if (bRes > 0)
                {
                    do
                    {
                        FILETIME creation = new FILETIME();
                        FILETIME exit = new FILETIME();
                        FILETIME kernel = new FILETIME();
                        FILETIME user = new FILETIME();
                        uint hThread = te.th32ThreadID;
                        if (GetThreadTimes(hThread,
                                              out creation,
                                              out exit,
                                              out kernel,
                                              out user))
                        {
                            threadtimes t = new threadtimes(user, kernel);// = { kernel, user };
                            //t.kernel = kernel;
                            //t.user = user;
                            process_list[te.th32ThreadID] = new thread(te.th32OwnerProcessID, te.th32ThreadID, t);
                            //System.Diagnostics.Debug.WriteLine(te.th32OwnerProcessID.ToString() + ": " +
                            //    te.th32ThreadID.ToString("x08") +
                            //    ", " + DateTime.FromFileTime(t.kernel).Ticks.ToString() +
                            //    ", " + DateTime.FromFileTime(t.user).Ticks.ToString()
                            //    );
                        }
                    } while (Thread32Next(snapshot, out te) > 0);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("error=" + Marshal.GetLastWin32Error());
                }

                CloseToolhelp32Snapshot(snapshot);
            }
            SetProcPermissions(old_permissions);
            return process_list;
        }
Example #4
0
        public threadStatistic(UInt32 id, UInt32 thID, threadtimes tht, UInt32 _duration, long _timestamp)
        {
            dwOwnerProcID = id;
            thread_times = tht;
            dwThreadID = thID;
            if (thID == 0)
                System.Diagnostics.Debugger.Break();
			duration=_duration;
			timestamp=_timestamp;
        }