3

这个问题中,我想用DbgCommand("dt ...")API 调用替换,PYKD命令typedVar()来救援。

结果,我的 heap_stat 脚本(以m_nSizem_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,我还是想知道如何使用它,用于调查目的。

4

1 回答 1

1

targetHeapIterator() - 仅用于托管堆,不能直接创建,只能通过特殊类创建。

for entry in targetProcess.getManagedHeap().entries():
    pass # enumerate managed heap

要枚举本机堆,您需要编写自己的脚本。

也许它对你有用: https ://githomelab.ru/pykd/pykdwin

这个包有堆枚举器但有限制:

  • 不支持 LFH
  • 不支持段堆

来自文档的样本:

from pykdwin.heap import *
for heap in get_heaps():
    for entry in heap.entries():
        print( hex(entry.address), entry.size )
于 2018-11-22T08:26:51.760 回答