问题
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
The code I wrote is the following:
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)
The output:
< type 'int'>
< type 'int'>
< type 'int'>
< type 'NoneType'>
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?
回答1:
The second parameter is called default, and it's stored as an attribute also called default.
b = BitField("foo",0x0,2)
b.default # 0
回答2:
Try .default attribute for BitField instances.
来源:https://stackoverflow.com/questions/6692411/scapy-bitfield-and-type-question