add utility to inspect gzip'ed payload

main
William Perron 10 months ago
parent 2fd259c162
commit aea9ae7ce4
Signed by: wperron
GPG Key ID: BFDB4EF72D73C5F2

@ -0,0 +1,59 @@
package gziputil
import (
"encoding/binary"
"fmt"
)
type Gzip struct {
magic []byte
cm byte
flg byte
mtime uint32
xfl byte
os byte
xlen uint16
xflds []byte
crc32 uint32
isize uint32
rest []byte
trailer []byte
}
func explainGzip(bs []byte) Gzip {
g := Gzip{
magic: bs[0:2],
cm: bs[2],
flg: bs[3],
mtime: binary.BigEndian.Uint32(bs[4:8]),
xfl: bs[8],
os: bs[9],
}
offset := 10
if g.xfl&2 == 1 {
g.xlen = binary.BigEndian.Uint16(bs[offset : offset+2])
offset += 2
g.xflds = bs[offset : offset+int(g.xlen)]
offset += int(g.xlen)
}
g.crc32 = binary.BigEndian.Uint32(bs[offset : offset+4])
offset += 4
g.isize = binary.BigEndian.Uint32(bs[offset : offset+4])
offset += 4
g.rest = bs[offset : len(bs)-8]
offset = len(bs) - 8
g.trailer = bs[offset:]
return g
}
func (g Gzip) String() string {
return fmt.Sprintf("magic=%04x cm=%02x flg=%02x mtime=%d xfl=%02x os=%02x xlen=%d crc32=%d isize=%d rest=%x trailer=%08x", g.magic, g.cm, g.flg, g.mtime, g.xfl, g.os, g.xlen, g.crc32, g.isize, g.rest, g.trailer)
}
Loading…
Cancel
Save