首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用PYKD读取堆

如何使用PYKD读取堆
EN

Stack Overflow用户
提问于 2018-11-20 12:45:12
回答 1查看 199关注 0票数 3

this question中,我想用API调用代替DbgCommand("dt ..."),而PYKD命令typedVar()来拯救它。

因此,我的heap_stat脚本(用m_nSizem_nCount信息扩展)现在运行速度快了三倍。

关于您的信息,我已经完成了计算STL集合中成员数量的替换操作:

代码语言:javascript
复制
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

由于这一成功,我想用API调用替换其他DbgCommand请求。

对于dbgCommand('!heap -h 0')来说,这似乎不是那么简单(一些例子):

代码语言:javascript
复制
>>> 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)?

即使targetHeap()不能作为!heap -h 0的替代品,我仍然想知道如何使用它来进行调查。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-22 08:26:51

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

代码语言:javascript
复制
for entry in targetProcess.getManagedHeap().entries():
    pass # enumerate managed heap

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

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

这个包有堆驱动程序,但有限制:

  • 不支持LFH
  • 不支持段堆。

来自医生的样本:

代码语言:javascript
复制
from pykdwin.heap import *
for heap in get_heaps():
    for entry in heap.entries():
        print( hex(entry.address), entry.size )
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53393285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档