【发布时间】:2013-12-16 18:15:28
【问题描述】:
import my_debugger
from my_debugger_defines import *
debugger = my_debugger.debugger()
pid = raw_input("Enter the PID of the process to attach to: ")
debugger.attach(int(pid))
list = debugger.enumerate_threads()
for thread in list:
thread_context = debugger.get_thread_context(thread)
print "[*] Dumping registers for thread ID: 0x%08x" % thread
print "[**] EIP: 0x%08x" % thread_context.Eip
print "[**] ESP: 0x%08x" % thread_context.Esp
print "[**] EBP: 0x%08x" % thread_context.Ebp
print "[**] EAX: 0x%08x" % thread_context.Eax
print "[**] EBX: 0x%08x" % thread_context.Ebx
print "[**] ECX: 0x%08x" % thread_context.Ecx
print "[**] EDX: 0x%08x" % thread_context.Edx
print "[*] END DUMP"
debugger.detach()
上面是我的测试程序,它产生'bool'对象不可迭代错误并引用第12行:
for thread in list:
我对可迭代对象做了一些研究,基本上发现它必须能够用不同的值重复自己(如果我错了请纠正我,我的编程知识很薄弱)。我不知道如何修复代码以使其正常工作。我已经做了很多谷歌搜索,但我没有足够的经验来参考类似的问题并将其应用于我自己的代码。这是直接出书的代码,所以我只是想知道我是否犯了一个简单的错误,或者它是否更复杂。
这里也是枚举线程的定义函数
def enumerate_threads(self):
thread_entry = THREADENTRY32()
thread_list = []
snapshot = kernel32.CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, self.pid)
if snapshot is not None:
thread_entry.dwSize = sizeof(thread_entry)
success = kernel32.Thread32First(snapshot, byref(thread_entry))
while success:
if thread_entry.th32OwnerProcessID == self.pid:
thread_list.append(thread_entry.th32ThreadID)
success = kernel32.Thread32Next(snapshot, byref(thread_entry))
kernel32.CloseHandle(snapshot)
return thread_list
else:
return False
如果您需要更多信息,请告诉我。我很感激任何帮助。提前致谢。
【问题讨论】:
-
除了任何答案之外,您几乎肯定不想要名为
list的变量。它隐藏了一个内置函数。