Scapy BitField and type() question

☆樱花仙子☆ 提交于 2019-12-11 17:52:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!