Skip to content

Commit

Permalink
caff: minor formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronsor committed Aug 18, 2023
1 parent 6d10a25 commit 23e660f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions format/caff/caff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func init() {
const (
imageFormatUnknown = 0x00
imageFormatPNG = 0x01
imageFormatNoPreview = 0x7F
imageFormatNoPreview = 0x7f
)

const (
colorTypeUnknown = 0x00
colorTypeARGB = 0x01
colorTypeRGB = 0x02
colorTypeNoPreview = 0x7F
colorTypeNoPreview = 0x7f
)

const (
Expand Down Expand Up @@ -88,8 +88,8 @@ func decodeCAFF(d *decode.D) any {

var obfsKey uint64

obfsU8 := func(d *decode.D) uint64 { return d.U8() ^ (obfsKey & 0xFF) }
obfsU32 := func(d *decode.D) uint64 { return d.U32() ^ (obfsKey & 0xFFFFFFFF) }
obfsU8 := func(d *decode.D) uint64 { return d.U8() ^ (obfsKey & 0xff) }
obfsU32 := func(d *decode.D) uint64 { return d.U32() ^ (obfsKey & 0xffff_ffff) }
obfsU64 := func(d *decode.D) uint64 { return d.U64() ^ (obfsKey<<32 | obfsKey) }
obfsBool := func(d *decode.D) bool { return obfsU8(d) != 0 }

Expand All @@ -98,7 +98,7 @@ func decodeCAFF(d *decode.D) any {
for {
x := obfsU8(d)
v <<= 7
v |= (x & 0x7F)
v |= (x & 0x7f)
if (x >> 7) == 0 {
return
}
Expand Down Expand Up @@ -188,10 +188,12 @@ func decodeCAFF(d *decode.D) any {
d.FieldRootBitBuf("compressed", br)

// Offset 0x26: skip ZIP entry header; there's nothing useful in it and it's always the same
infBytes, err := io.ReadAll(flate.NewReader(bytes.NewReader(rawBytes[0x26:])))
if err == nil {
infBr := bitio.NewBitReader(infBytes, -1)
_, _, _ = d.TryFieldFormatBitBuf("uncompressed", infBr, &probeGroup, format.Probe_In{})
if len(rawBytes) > 0x26 {
infBytes, err := io.ReadAll(flate.NewReader(bytes.NewReader(rawBytes[0x26:])))
if err == nil {
infBr := bitio.NewBitReader(infBytes, -1)
d.TryFieldFormatBitBuf("uncompressed", infBr, &probeGroup, format.Probe_In{})
}
}
}
})
Expand Down

0 comments on commit 23e660f

Please sign in to comment.