-
Notifications
You must be signed in to change notification settings - Fork 22
/
common.go
75 lines (63 loc) · 1.58 KB
/
common.go
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
67
68
69
70
71
72
73
74
75
package apkparser
import (
"encoding/binary"
"io"
)
// frameworks/base/libs/androidfw/include/androidfw/ResourceTypes.h
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
chunkHeaderSize = (2 + 2 + 4)
)
type ResAttr struct {
NamespaceId uint32
NameIdx uint32
RawValueIdx uint32
Res ResValue
}
type ResValue struct {
Size uint16
Res0 uint8 // padding
Type AttrType
Data uint32
}
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
}