Scapy BitField 和 type() 问题 [英] Scapy BitField and type() question
问题描述
我正在为 scapy 编写插件,但遇到了问题.我不得不稍微修改原始的 scapy 代码(每个类都继承自对象)修改后的代码可以在这里找到:http://pastebin.com/pjcL1KJv
I'm writing an addon for scapy, and encountered a problem. I had to slightly modify the original scapy code (every class is inheriting from object) The modified code can be found here: http://pastebin.com/pjcL1KJv
我写的代码如下:
class Foo():
array=[ BitField("foo",0x0,2),
BitField("foo1",0x0,2),
BitField("bar",0x0,2),
BitField("blub",None,2)
]
def returnArr(a):
for i in a.array:
print type(i.default)
if __name__ == "__main__":
a=Foo()
a.blub=0x23
returnArr(a)
输出:
<输入'int'>
<输入'int'>
<输入'int'>
<输入无类型">
我的问题:是否可以检测 BitField("foo",0x0,2)
的第二个参数是 0x0
还是其他什么?如果可能,我会怎么做?如果没有,为什么?
My question:
Is it possible to detect if the second paremeter of BitField("foo",0x0,2)
is 0x0
or something else? If it is possible, how would I do that? If not, why?
推荐答案
第二个参数称为 default
,它作为属性存储,也称为 default.
The second parameter is called default
, and it's stored as an attribute also called default.
b = BitField("foo",0x0,2)
b.default # 0
这篇关于Scapy BitField 和 type() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!