我试图将字段描述为偏移量并访问其数据
例如:
fields_desc = [LEShortField("structure_size",0),
ByteField("flags",0),
**LEShortField("blob_offset",0)**,
LEFieldLenField("user_name_length", 0),
LEShortField("user_name_maxlength", 0),
**LEIntField("user_name_offset", 0)**]
我需要使用变量blob_offset并将其添加为user_name_offset才能提取用户名。
我该怎么做?我没有找到特别的变量...
谢谢
答案 0 :(得分:1)
好吧,假设您的“ blob”和用户名恰好在您指定的数据包之后,您并不能完全说出数据包的外观,您可以尝试执行以下操作:
fields_desc = [LEShortField("structure_size",0),
ByteField("flags",0),
LEFieldLenField("blob_offset",0, length_of="blob_offset_pad", fmt="!H"),
LEFieldLenField("user_name_length", 0, length_of="user_name"),
LEShortField("user_name_maxlength", 0),
LEFieldLenField("user_name_offset", 0, length_of="user_name", fmt="!I"),
StrFixedLenField("blob_offset_pad", 0, length_from = lambda pkt: pkt.blob_offset),
StrFixedLenField("user_name_offset_pad", 0, length_from = lambda pkt: pkt.user_name_offset),
StrFixedLenField("user_name", "", length_from= lambda pkt: pkt.user_name_length)]
再次无法真正测试此内容,因为您未提供任何有用的示例