File: common.go

package info (click to toggle)
golang-github-avast-apkparser 0.0~git20190516.3b8c5ef-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 244 kB
  • sloc: xml: 101; sh: 6; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package apkparser

import (
	"encoding/binary"
	"io"
)

const (
	chunkNull          = 0x0000
	chunkStringTable   = 0x0001
	chunkTable         = 0x0002
	chunkAxmlFile      = 0x0003
	chunkResourceIds   = 0x0180
	chunkTablePackage  = 0x0200
	chunkTableType     = 0x0201
	chunkTableTypeSpec = 0x0202
	chunkTableLibrary  = 0x0203

	chunkMaskXml     = 0x0100
	chunkXmlNsStart  = 0x0100
	chunkXmlNsEnd    = 0x0101
	chunkXmlTagStart = 0x0102
	chunkXmlTagEnd   = 0x0103
	chunkXmlText     = 0x0104

	attrIdxNamespace = 0
	attrIdxName      = 1
	attrIdxString    = 2
	attrIdxType      = 3
	attrIdxData      = 4
	attrValuesCount  = 5

	chunkHeaderSize = (2 + 2 + 4)
)

type AttrType uint8

const (
	AttrTypeNull          AttrType = 0x00
	AttrTypeReference              = 0x01
	AttrTypeAttribute              = 0x02
	AttrTypeString                 = 0x03
	AttrTypeFloat                  = 0x04
	AttrTypeIntDec                 = 0x10
	AttrTypeIntHex                 = 0x11
	AttrTypeIntBool                = 0x12
	AttrTypeIntColorArgb8          = 0x1c
	AttrTypeIntColorRgb8           = 0x1d
	AttrTypeIntColorArgb4          = 0x1e
	AttrTypeIntColorRgb4           = 0x1f
)

func parseChunkHeader(r io.Reader) (id, headerLen uint16, len uint32, err error) {
	if err = binary.Read(r, binary.LittleEndian, &id); err != nil {
		return
	}

	if err = binary.Read(r, binary.LittleEndian, &headerLen); err != nil {
		return
	}

	if err = binary.Read(r, binary.LittleEndian, &len); err != nil {
		return
	}
	return
}