使用lz4解压缩十六进制字节数据

时间:2017-05-23 06:27:43

标签: python hex byte compression lz4

首先,使用tcpdump捕获udp广播数据,其中一个数据包(所有数据包类似)看起来像这样。

11:14:54.952531 IP (tos 0x0, ttl 64, id 20499, offset 0, flags [none], proto UDP (17), length 540)
192.168.200.20.28190 > 233.1.2.5.28190: [udp sum ok] UDP, length 512
0x0000:  4500 021c 5013 0000 4011 b4fa c0a8 c814  E...P...@.......
0x0010:  e901 0205 6e1e 6e1e 0208 500d 0220 0001  ....n.n...P.....
0x0020:  00aa 1a02 595a 2a2a 3132 3300 4000 0546  ....YZ**123.@..F
0x0030:  5573 ae00 001c 2b40 2802 01c9 2520 00e0  Us....+@(...%...
0x0040:  4c01 a2fd 3520 a002 00cc 0046 c1c2 000c  L...5......F....
0x0050:  03b5 3b00 1b00 1f80 bc00 0896 bb80 41e6  ..;...........A.
0x0060:  065b f100 0003 0002 0001 6da0 ffff feed  .[........m.....
0x0070:  0001 0000 4160 25e8 7e09 605d de40 7f00  ....A`%.~.`].@..
0x0080:  79e0 4025 d960 4d2e 6025 d440 4e01 5a60  y.@%.`M.`%.@N.Z`
0x0090:  25f2 40ef 034b c040 27f7 0005 0026 3900  %.@..K.@'....&9.
0x00a0:  5dfc 609d 5d40 4dff 001d 0400 4dfd 409c  ].`.]@M.....M.@.
0x00b0:  02ff 0641 1aa9 825c 0141 32f8 4060 1c61  ...A...\.A2.@`.a
0x00c0:  b460 fc61 3460 1c62 4c11 0000 0000 0000  .`.a4`.bL.......
0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0130:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0140:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0150:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0160:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0170:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0180:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0190:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x01f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0200:  0000 0000 0000 0000 0000 0000 0000 0000  ................
0x0210:  0000 0000 0000 0000 0000 0000            ............

从这里开始,通过获取数据块,下面给出了使用LZ4压缩算法编码的字节压缩数据。

有关如何解压缩和获取实际数据的任何建议, 压缩数据看起来像这样。

0220 0001 00aa 1a02 595a 2a2a 3132 3300 4000 0546 5573 ae00 001c 2b40 2802 01c9 2520 00e0 4c01 a2fd 3520 a002 00cc 0046 c1c2 000c 03b5 3b00 1b00 1f80 bc00 0896 bb80 41e6 065b f100 0003 0002 0001 6da0 ffff feed 0001 0000 4160 25e8 7e09 605d de40 7f00 79e0 4025 d960 4d2e 6025 d440 4e01 5a60 25f2 40ef 034b c040 27f7 0005 0026 3900 5dfc 609d 5d40 4dff 001d 0400 4dfd 409c 02ff 0641 1aa9 825c 0141 32f8 4060 1c61 b460 fc61 3460 1c62 4c11 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ....

1 个答案:

答案 0 :(得分:2)

  

问题:...使用LZ4压缩算法进行编码。   有关如何解压缩的任何建议......

试试这个模块:python-lz4 Quickstart

推荐使用的绑定是LZ4帧格式。使用框架包的最简单方法是导入压缩和解压缩功能:

>>> import os
>>> from lz4.frame import compress, decompress
>>> input_data = os.urandom(20 * 128 * 1024)  # Read 20 * 128kb
>>> compressed = compress(input_data)
>>> decompressed = decompress(compressed) 
>>> decompressed == input_data
Out[6]: True