如何在Python相关库中转义星号?
我正在使用PYKD,一个用于为Windbg编写Python脚本的库 处理包含星号的类型名称时,如何在Python相关库中转义星号?,python,regex,escaping,windbg,pykd,Python,Regex,Escaping,Windbg,Pykd,我正在使用PYKD,一个用于为Windbg编写Python脚本的库 处理包含星号的类型名称时,typedVar,其中一个函数似乎不起作用: >>> print typedVar('CMap<int,int,void **,void **>', 0x0054ac10).m_nCount Traceback (most recent call last): File "<console>", line 1, in <module> TypeE
typedVar
,其中一个函数似乎不起作用:
>>> print typedVar('CMap<int,int,void **,void **>', 0x0054ac10).m_nCount
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeException: CMap<int,int,void **,void **> : invalid type name
(在Windbg会话中):
进一步使用最新的PYKD库后进行编辑
不幸的是,正如您从以下摘录中看到的,仍然存在一个问题:
0:000> .load pykd.pyd
0:000> .chain
Extension DLL search Path:
...
Extension DLL chain:
pykd.pyd: image 0.3.4.2, API 1.0.0, built Sat Nov 17 13:06:54 2018
[path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext\pykd.pyd]
...
0:000> !py
>>> dprintln("%d" % typedVar('Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>', 0x064ad440).m_nCount)
2
=> An asterisk in the type name can sometimes be handled
>>> dprintln("%d" % typedVar('Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>', 0x064ad328).m_nCount)
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: typed var has no field 'm_nCount'
=> But sometimes there still are issues.
The error message clearly shows that the typename is known.
dt
和dx
似乎提到该特定CMap存在一个问题:
0:000> dt 0x064ad328 CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
0:000> dt 0x064ad328 CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *> m_nCount
Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
0:000> dx (CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>*) 0x064ad328
Error: Unable to find type 'CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *> *' for cast.
0:000>dt 0x064ad328 CMap
应用CMap
0:000>dt 0x064ad328 CMap m\u计数
应用CMap
0:000>dx(CMap*)0x064ad328
错误:找不到强制转换的类型“CMap*”。
但是,符号似乎没有问题:
0:000> x /2 Application!CMap<*vftable*
...
0152e944 Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>::`vftable'
...
01503444 Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::`vftable'
0:000>x/2应用程序!CMap无法发表评论,但您可以尝试此处解释的r'string'
或者,如果可以,将指针交换为任何无符号64位数据类型 typedVar不解释类型名称。必须使用与符号信息中包含的类型名称相同的类型名称
尝试使用dt命令查找它:
dt CMap*
或使用pykd:
print( "\n".join( module('ModuleName').enumTypes('CMap*') )
我相信它看起来会像“CMap”(没有任何空间)这是一个pykd错误:
它将在下一版本中修复尝试打印类型信息:
>>>print( typeInfo('Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION,_RTL_CRITICAL_SECTION *>') )
打印(typeInfo('Application!CMap'))
你试过typedVar(r'CMap***…)
(注意r
)?@Jan:谢谢你的快速回复,但是添加r
,或u
,或ru
,…,并不能解决问题。可能相关:@ThomasWeller:我的问题是我原来问题的结果“,在访问了你提到的URL之后,我相信你在正确的轨道上解决了我最初的问题。不幸的是,我的试用,使用“@!”前缀似乎不起作用。你能看看我原来的问题,看看如何处理吗?提前谢谢。哇。不幸的是,我的机器坏了。我将在虚拟机中重试。你是否可以提供C++代码,这样我就可以专注于Pykd部分,不必为实现而烦恼?谢谢快速回复,但是正如我提到的,我遵循了URL中提到的建议,但是我没有成功。谢谢你的回复。如果你回答我最初的问题“”,我将为此奖励你。您知道该问题是否仅适用于void*
或其他指针成员?任何带有*或[]的模板都会影响pykd更新为0.3.4.2 pip安装pykd谢谢。我已经下载了最新版本,我可以确认它是否有效:typedVar()
函数现在也可以正常工作,对于包含星号的模板也是如此。感谢您的确认谢谢您的快速回复。我已对问题进行了相应的编辑,请参见“在ussrhero的新提案之后进行编辑”。是否尝试与dt/dx/?的输出进行比较??windbg打印出来的结果正确吗?根据您上次的评论,我已经编辑了这个问题:问题似乎是由windbg引起的,而不是由PYKD引起的,因为windbg命令dt
和dx
也没有给出正确的结果。同时,我发现问题是由缺少符号引起的(所提到的对象嵌入了一个库中,该库的符号不包括在应用程序的全局符号中),因此可以结束这个问题。
>>> print(typeInfo('Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>'))
class/struct : CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int> Size: 0x1c (28)
+0000 __VFN_table : VTable*
=0000000000 classCObject : CRuntimeClass
+0004 m_pHashTable : CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::CAssoc**
+0008 m_nHashTableSize : UInt4B
+000c m_nCount : Int4B
+0010 m_pFreeList : CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::CAssoc*
+0014 m_pBlocks : CPlex*
+0018 m_nBlockSize : Int4B
>>> print(typeInfo('Application!NonExisting_Class'))
Traceback (most recent call last):
File "<console>", line 1, in <module>
SymbolException: 'NonExisting_Class' - symbol not found
0:000> dt 0x064ad440 CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>
Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>
+0x000 __VFN_table : 0x01503444
+0x004 m_pHashTable : 0x06ab9ad0 -> (null)
+0x008 m_nHashTableSize : 0x186ab
+0x00c m_nCount : 0n2
+0x010 m_pFreeList : 0x063c953c CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::CAssoc
+0x014 m_pBlocks : 0x063c9518 CPlex
+0x018 m_nBlockSize : 0n10
0:000> dt 0x064ad440 CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int> m_nCount
Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>
+0x00c m_nCount : 0n2
0:000> dx (CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>*) 0x064ad440
(CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>*) 0x064ad440 : 0x64ad440 [Type: CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int> *]
[+0x004] m_pHashTable : 0x6ab9ad0 [Type: CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::CAssoc * *]
[+0x008] m_nHashTableSize : 0x186ab [Type: unsigned int]
[+0x00c] m_nCount : 2 [Type: int]
[+0x010] m_pFreeList : 0x63c953c [Type: CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::CAssoc *]
[+0x014] m_pBlocks : 0x63c9518 [Type: CPlex *]
[+0x018] m_nBlockSize : 10 [Type: int]
0:000> dt 0x064ad328 CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
0:000> dt 0x064ad328 CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *> m_nCount
Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>
0:000> dx (CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>*) 0x064ad328
Error: Unable to find type 'CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *> *' for cast.
0:000> x /2 Application!CMap<*vftable*
...
0152e944 Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION *,_RTL_CRITICAL_SECTION *>::`vftable'
...
01503444 Application!CMap<ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,wchar_t const *,unsigned int,unsigned int>::`vftable'
dt CMap*
print( "\n".join( module('ModuleName').enumTypes('CMap*') )
>>>print( typeInfo('Application!CMap<unsigned int,unsigned int,_RTL_CRITICAL_SECTION,_RTL_CRITICAL_SECTION *>') )