如何在自定义Scapy类中设置我的字节大小?

发布于 2025-02-06 15:24:49 字数 661 浏览 1 评论 0原文

有人可以帮我提供示例代码。 我想使用Scapy创建此数据包结构:

MyPacketStructure:
  field1: 2 bytes
  field2: 16 bytes
  field3: 12 bytes
  field4: 17 bytes
  data: 83 bytes

如何为上述数据包结构定义SCAPY类?

class MyPacketStructure(Packet):
    what type do i use to set ("field1") for 2 bytes
    what type do i use to set ("field2") for 16 bytes
    what type do i use to set ("field3") for 12 bytes
    what type do i use to set ("field4") for 17 bytes
    what type do i use to set ("data") for 83 bytes

我看到字节菲尔德,但这只是一个字节。哪个SCAPY数据类型让我设置该字段的字节数。

对于数据字段或有效载荷,推荐的数据类型是什么?如果我只有43个字节会怎样?如何为数据字段添加其他40个字节?

任何帮助将不胜感激。先感谢您。

Can someone please help me with an example code.
I would like to use scapy to create this packet structure:

MyPacketStructure:
  field1: 2 bytes
  field2: 16 bytes
  field3: 12 bytes
  field4: 17 bytes
  data: 83 bytes

How do I define a scapy class for the above packet structure?

class MyPacketStructure(Packet):
    what type do i use to set ("field1") for 2 bytes
    what type do i use to set ("field2") for 16 bytes
    what type do i use to set ("field3") for 12 bytes
    what type do i use to set ("field4") for 17 bytes
    what type do i use to set ("data") for 83 bytes

I see ByteField but it's only one byte. Which scapy datatype let's me set the number of bytes for that field.

For the data field or payload, what is the recommended datatype? What happens if i only 43 bytes? How do I pad the other 40 bytes for the data field?

Any help would be appreciated. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文