How to decompress zlib format package in dissector?
asked Sep 13 '25
I wrote a dissector. I need to decompress zlib format package when analyzing data. I have tried:
- local zlib = require("zlib") - got an error saying the package was not found;
- local zlib = require("zlib1") - got an error saying it was not a valid dll.
Currently, I am using a solution of calling Python code, but this is very inefficient. Some of my code is as follows:
local compressed_data = buffer(40, data_length - 36)
local compressed_hex = tostring(compressed_data:bytes():tohex())
local handle = io.popen("python -c \"import zlib,binascii,sys;print(zlib.decompress(binascii.unhexlify(sys.argv[1])).decode('utf-8'))\" " .. compressed_hex, "r")
local content = handle:read("*a")
handle:close()
Could you please tell me how to solve this problem?

Thank you very much for your solution. I have solved this problem by using tvbrange:uncompress_zlib(name).
function p_xxxx_proto.dissector(tvb, pinfo, tree)
local subtree = tree:add(p_xxxx_proto, tvb:range(offset), "xxxxxxxxxx")
local compressed_data = tvb:range(40, data_length - 36)
subtree:add(f_data, compressed_data:uncompress_zlib(compressed_data:string()))