动态(根据先前的 Protofield 值)基于 valuestring 的

我正在使用 lua 开发 wireshark 插件。

我有一个 Protofield,它的 valuestring 表会根据先前字段的值而发生变化。我不知道如何在我正在开发的 lua wireshark 插件中干净地完成这项工作。 例:

parent_type = Protofield.uint8("myProto.myParentField", "父亲", base.HEX, {"1", "2"}, 0xf0, "")
child_type = Protofield.uint8("myProto.myChildField", "孩子", base.HEX, {"如果父亲为1,则为值3,否则为值5", "如果父亲为1,则为值4,否则为值6"}, 0x0f, "")

现在,我希望能够根据 parent_type 的值决定 child_type 字段的 valuestring。

我能在_dissector:call_ 方法中追加_text 到 child_type,但它的格式如下:

.... ...1 = 孩子:(0x01)3

而我希望它是(有点苛刻):

.... ...1 = 孩子:3(0x01)

如果我使用 _:set_text_,则整个文本 “.... ...1 = 孩子:(0x01)” 被替换为 “3”

我试过使用字符串库操作,但也无法使它们正常工作。

非常感谢任何帮助。

原文链接 https://stackoverflow.com/questions/69713633

点赞
stackoverflow用户20246743
stackoverflow用户20246743
parent_type = Protofield.uint8("myProto.myParentField", "Parent", base.HEX, {"1", "2"}, 0xf0, "")

child_type_for_p1 = Protofield.uint8("myProto.myChildField", "Child", base.HEX, {"3", "5"}, 0x0f, "")
child_type_for_p2 = Protofield.uint8("myProto.myChildField", "Child", base.HEX, {"4", "6"}, 0x0f, "")

如果 v_parent_type == 1 then
    packet_detail:add(child_type_for_p1, ...)
elseif v_parent_type == 2 then
    packet_detail:add(child_type_for_p2, ...)
end

以上代码定义了三个字段:parent_type 作为母字段,child_type_for_p1child_type_for_p2 作为子字段。父字段的类型为 uint8,名称为 "myProto.myParentField",显示名称为 "Parent",以16进制表示,可取值为 "1" 和 "2",默认值为 0xf0,没有注释。

子字段 child_type_for_p1child_type_for_p2 类型均为 uint8,名称为 "myProto.myChildField",显示名称为 "Child",以16进制表示,可取值分别为 {"3", "5"} 和 {"4", "6"},默认值为 0x0f,没有注释。根据 v_parent_type 的值来添加不同的子字段到 packet_detail

2022-10-15 06:34:28