예제 #1
0
    def enumerate_threads_setup_owners(self):
        # Enumerating threads is a special operation concerning the owner process.
        # We may not be able to retrieve the name of the owning process by normal way
        # (as we need to get a handle on the process)
        # So, this implementation of enumerate_thread also setup the owner with the result of enumerate_processes
        dbgprint("Enumerating threads with CreateToolhelp32Snapshot and setup owner", "SLOW")

        # One snap for both enum to be prevent race
        snap = winproxy.CreateToolhelp32Snapshot(gdef.TH32CS_SNAPTHREAD | gdef.TH32CS_SNAPPROCESS, 0)

        process_entry = gdef.PROCESSENTRY32()
        process_entry.dwSize = ctypes.sizeof(process_entry)
        winproxy.Process32First(snap, process_entry)
        processes = []
        processes.append(process.WinProcess._from_PROCESSENTRY32(process_entry))
        while winproxy.Process32Next(snap, process_entry):
            processes.append(process.WinProcess._from_PROCESSENTRY32(process_entry))

        # Forge a dict pid -> process
        proc_dict = {proc.pid: proc for proc in processes}

        thread_entry = gdef.THREADENTRY32()
        thread_entry.dwSize = ctypes.sizeof(thread_entry)
        threads = []
        winproxy.Thread32First(snap, thread_entry)
        parent = proc_dict[thread_entry.th32OwnerProcessID]
        threads.append(process.WinThread._from_THREADENTRY32(thread_entry, owner=parent))
        while winproxy.Thread32Next(snap, thread_entry):
            parent = proc_dict[thread_entry.th32OwnerProcessID]
            threads.append(process.WinThread._from_THREADENTRY32(thread_entry, owner=parent))
        winproxy.CloseHandle(snap)
        return threads
예제 #2
0
 def enumerate_processes():
     process_entry = PROCESSENTRY32()
     process_entry.dwSize = ctypes.sizeof(process_entry)
     snap = winproxy.CreateToolhelp32Snapshot(windef.TH32CS_SNAPPROCESS, 0)
     winproxy.Process32First(snap, process_entry)
     res = []
     res.append(process.WinProcess._from_PROCESSENTRY32(process_entry))
     while winproxy.Process32Next(snap, process_entry):
         res.append(process.WinProcess._from_PROCESSENTRY32(process_entry))
     return res
예제 #3
0
 def enumerate_processes():
     process_entry = WinProcess()
     process_entry.dwSize = ctypes.sizeof(process_entry)
     snap = winproxy.CreateToolhelp32Snapshot(windef.TH32CS_SNAPPROCESS, 0)
     winproxy.Process32First(snap, process_entry)
     res = []
     res.append(utils.swallow_ctypes_copy(process_entry))
     while winproxy.Process32Next(snap, process_entry):
         res.append(utils.swallow_ctypes_copy(process_entry))
     return res
예제 #4
0
 def enumerate_processes():
     dbgprint("Enumerating processes with CreateToolhelp32Snapshot", "SLOW")
     process_entry = gdef.PROCESSENTRY32()
     process_entry.dwSize = ctypes.sizeof(process_entry)
     snap = winproxy.CreateToolhelp32Snapshot(gdef.TH32CS_SNAPPROCESS, 0)
     winproxy.Process32First(snap, process_entry)
     res = []
     res.append(process.WinProcess._from_PROCESSENTRY32(process_entry))
     while winproxy.Process32Next(snap, process_entry):
         res.append(process.WinProcess._from_PROCESSENTRY32(process_entry))
     winproxy.CloseHandle(snap)
     return res