我正在使用 PYKD 进行转储分析。PYKD 库用于 heap_stat 脚本,我想以更具交互性的方式使用 PYKD 库,如下所示:
Windbg prompt>!py
Input>dbgCommand("x /2 *!CStringArray*vftable*")
这很好用(我知道这没用,我只是想证明它有效)。
但是,heap_stat 脚本包含以下源代码:
try:
vftable_candidate = ptrPtr(ptr) # which pointer value is present on that spot in memory?
dprintln("DDS vftable_candidate [%08x], ptr value [%d], ptr pointer [%08x]" % (vftable_candidate, ptr, ptr))
except:
continue
当我以交互方式尝试时,这似乎不起作用:
Windbg prompt>!py
Input>ptrPtr(48806712)
这会产生以下错误,让我退出 Python 会话:
File "<console>", line 1
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\Lib\code.py", line 243, in interact
more = self.push(line)
File "C:\Python27\Lib\code.py", line 265, in push
more = self.runsource(source, self.filename)
File "C:\Python27\Lib\code.py", line 79, in runsource
self.showsyntaxerror(filename)
File "C:\Python27\Lib\code.py", line 139, in showsyntaxerror
map(self.write, list)
File "C:\Python27\Lib\code.py", line 171, in write
sys.stderr.write(data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 11: ordinal not in range(128)
没关系:将这个函数调用包装在子句中是有原因的try..except
,所以现在让我们尝试将这个函数包装try..except
在交互式 Python 会话中的子句中:
Windbg prompt>!py
Input>try: ptrPtr(48806712) except: continue
=> 这给出了同样的错误,尽管try..except
. 这很可能是由于缩进错误,但另一方面,交互式 Windbg Python 会话不允许多行,所以我不能使用 Python 缩进。
有没有办法try..except
在 Windbg PYKD Python 会话中使用子句?
提前致谢
Ps 为了您的理解:这种行为(被踢出交互式会话)似乎是 Windbg PYKD 的典型行为,您可以在以下命令提示符 Python 会话中看到:
Windows Prompt>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print 1/0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
>>>
如您所见,抛出了异常,但我没有被踢出 Python 会话(观看>>>
提示)。