用于HTTP的Lua解剖器,无法找到字符串结尾

问题描述 投票:1回答:1

我试图使用lua在wireshark中的HTTP协议中分离字符串数据,我没有成功找到字符串的结尾,这是我目前的

HTTP_protocol = Proto("ourHTTP", "HTTPProtocol")

first =ProtoField.string("HTTP_protocol.first", "first", base.ASCII)
second =ProtoField.string("HTTP_protocol.second", "second", base.ASCII)
HTTP_protocol.fields = {first}

function HTTP_protocol.dissector(buffer, pinfo, tree)
 length = buffer:len()

 if length ==0 then return end
pinfo.cols.protocol = HTTP_protocol.name
local subtree = tree:add(HTTP_protocol, buffer(), "HTTPProtocol data ")
local string_length

for i = 0, length - 1, 1 do
  if (buffer(i,1):uint() == '\r') then
    string_length = i - 0
    break
  end
end
subtree:add(first, buffer(0,string_length))

end
porttable = DissectorTable.get("tcp.port")
porttable:add(80, HTTP_protocol)

我已经尝试搜索'\ r','\ 0'和'\ n',但无论我仍然得到所有的字符串作为一个。有什么我做错了吗?

string http lua wireshark-dissector
1个回答
1
投票

你可以用0x0D代替。这是\r的ASCII码。所以它最终会成为

if (buffer(i,1):uint() == 0x0D) then

在Wireshark中:

Picture of Wireshark with proper lineshift

© www.soinside.com 2019 - 2024. All rights reserved.