在 Lua Wireshark 解析器中重新组装数据包。
2013-1-17 21:39:49
收藏:0
阅读:147
评论:1
我正在尝试为基于bplists的Safari远程调试协议编写解析器,并且已经有了一定的成功(当前代码在此处:https://github.com/andydavies/bplist-dissector)。
但是我在重新组装数据包方面遇到了困难。
通常,该协议会发送一个四字节的数据包,其中包含下一个数据包的长度,然后是带有bplist的数据包。
不幸的是,来自iOS模拟器的某些数据包不遵循此约定,四个字节要么附加到bplist数据包的前面,要么附加到前一个bplist数据包的末尾,或者数据包含有多个bplists。
我已经尝试使用desegment_len和desegment_offset重新组装它们,如下所示:
function p_bplist.dissector(buf, pkt, root)
-- length of data packet
local dataPacketLength = tonumber(buf(0, 4):uint())
local desiredPacketLength = dataPacketLength + 4
-- if not enough data indicate how much more we need
if desiredPacketLen > buf:len() then
pkt.desegment_len = dataPacketLength
pkt.desegment_offset = 0
return
end
-- have more than needed so set offset for next dissection
if buf:len() > desiredPacketLength then
pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
pkt.desegment_offset = desiredPacketLength
end
-- copy data needed
buffer = buf:range(4, dataPacketLen)
...
我在此尝试的是始终将大小字节强制为要解析的数据包的前四个字节,但它不起作用,我仍然会看到一个4字节的数据包,然后是一个_x_字节的数据包。
我可以想到其他管理前面的额外四个字节的方法,但是该协议包含一个查找表距离数据包末尾32个字节,因此需要一种准确地将数据包拆分为bplists的方法。
这是一个示例捕获:http://www.cloudshark.org/captures/2a826ee6045b # 338是一个示例,其中bplist大小在数据的开头,数据中有多个plists。
我是否做得对(在SO上查看其他问题和网络上的示例看起来是这样),或者是否有更好的方法?
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

TCP解析器packet-tcp.c有
tcp_dissect_pdus()函数,它用于循环解剖TCP流中的PDU;该函数假定PDU由包含足够信息以确定PDU长度的固定长度数据块,以及其余PDU组成。Lua API中没有这种函数,但这是一个很好的例子可以参考。
另一个例子。我在一年前的测试中使用了这个函数:
local slicer = Proto("slicer","Slicer") function slicer.dissector(tvb, pinfo, tree) local offset = pinfo.desegment_offset or 0 local len = get_len() -- for tests i used a constant, but can be taken from tvb while true do local nxtpdu = offset + len if nxtpdu > tvb:len() then pinfo.desegment_len = nxtpdu - tvb:len() pinfo.desegment_offset = offset return end tree:add(slicer, tvb(offset, len)) offset = nxtpdu if nxtpdu == tvb:len() then return end end end local tcp_table = DissectorTable.get("tcp.port") tcp_table:add(2506, slicer)