-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpropvalue.go
More file actions
102 lines (95 loc) · 2.09 KB
/
propvalue.go
File metadata and controls
102 lines (95 loc) · 2.09 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package msi
import (
"encoding/binary"
"fmt"
"io"
)
type PropertyValue struct {
Empty bool
Null bool
I1 int8
I2 int16
I4 int32
LpStr string
FileTime int64
}
func ReadPropValue(rdr io.ReadSeeker, codePage CodePage) (*PropertyValue, error) {
var typeNumber uint32
err := binary.Read(rdr, binary.LittleEndian, &typeNumber)
if err != nil {
return nil, err
}
switch typeNumber {
case 0:
return &PropertyValue{Empty: true}, nil
case 1:
return &PropertyValue{Null: true}, nil
case 2:
var value int16
err = binary.Read(rdr, binary.LittleEndian, &value)
if err != nil {
return nil, err
}
return &PropertyValue{I2: value}, nil
case 3:
var value int32
err = binary.Read(rdr, binary.LittleEndian, &value)
if err != nil {
return nil, err
}
return &PropertyValue{I4: value}, nil
case 16:
var value int8
err = binary.Read(rdr, binary.LittleEndian, &value)
if err != nil {
return nil, err
}
return &PropertyValue{I1: value}, nil
case 30:
var length uint32
err = binary.Read(rdr, binary.LittleEndian, &length)
if err != nil {
return nil, err
}
if length != 0 {
length = length - 1
}
var value = make([]byte, 0, length)
for i := 0; i < int(length); i++ {
var b uint8
err = binary.Read(rdr, binary.LittleEndian, &b)
if err != nil {
return nil, err
}
value = append(value, b)
}
var term uint8
err = binary.Read(rdr, binary.LittleEndian, &term)
if err != nil {
return nil, err
}
if term != 0 {
return nil, fmt.Errorf("invalid string terminator: %v", term)
}
str, err := codePage.Decode(value)
if err != nil {
return nil, err
}
return &PropertyValue{LpStr: str}, nil
case 64:
var value int64
err = binary.Read(rdr, binary.LittleEndian, &value)
if err != nil {
return nil, err
}
return &PropertyValue{FileTime: value}, nil
default:
return nil, fmt.Errorf("invalid property type: %v", typeNumber)
}
}
func (p *PropertyValue) MinimumVersion() PropertyFormatVersion {
if p.I1 == int8(PropertyFormatVersion1) {
return PropertyFormatVersion1
}
return PropertyFormatVersion0
}