在这个问题中,我想用DbgCommand("dt ...")
API 调用替换,PYKD
命令typedVar()
来救援。
结果,我的 heap_stat 脚本(以m_nSize
和m_nCount
信息扩展)现在运行速度快了三倍。
供您参考,我已完成此替换以计算 STL 集合中的成员数量:
Replace: collection_Size = dbgCommand(("dt 0x" + pointer_format + " %s m_nSize") % (ptr,type_name)).split(' : ').[-1].split('\n')[0]
By: collection_Size = typedVar(type_name, ptr).m_nSize
由于这次成功,我想DbgCommand
通过 API 调用替换其他请求。
对于 的情况dbgCommand('!heap -h 0')
,这似乎不是那么简单(一些例子):
>>> for t in targetHeapIterator():
... print t
...
Traceback (most recent call last):
File "<console>", line 1, in <module>
RuntimeError: This class cannot be instantiated from Python
>>> for t in targetHeap().entries:
... print t
...
Traceback (most recent call last):
File "<console>", line 1, in <module>
RuntimeError: This class cannot be instantiated from Python
>>> for t in targetProcess().getManagedHeap().entries:
... print t
...
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: 'instancemethod' object is not iterable
如何迭代我的进程堆(替换!heap -h 0
)?
PS 即使targetHeap()
不能代替!heap -h 0
,我还是想知道如何使用它,用于调查目的。