...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package comdoc
18
19 import (
20 "unicode/utf16"
21 )
22
23 type SecID int32
24 type DirType uint8
25 type Color uint8
26
27 const (
28 SecIDFree SecID = -1
29 SecIDEndOfChain SecID = -2
30 SecIDSAT SecID = -3
31 SecIDMSAT SecID = -4
32
33 DirEmpty DirType = 0
34 DirStorage DirType = 1
35 DirStream DirType = 2
36 DirRoot DirType = 5
37
38 Red Color = 0
39 Black Color = 1
40
41 byteOrderMarker uint16 = 0xfffe
42 msatInHeader = 109
43 )
44
45 var fileMagic = []byte{0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}
46
47
48 type Header struct {
49 Magic [8]byte
50 UID [16]byte
51 Revision uint16
52 Version uint16
53 ByteOrder uint16
54 SectorSize uint16
55 ShortSectorSize uint16
56 Reserved1 [6]byte
57 DirSectorCount uint32
58 SATSectors uint32
59 DirNextSector SecID
60 Reserved2 uint32
61 MinStdStreamSize uint32
62 SSATNextSector SecID
63 SSATSectorCount uint32
64 MSATNextSector SecID
65 MSATSectorCount uint32
66 MSAT [msatInHeader]SecID
67 }
68
69
70 type RawDirEnt struct {
71 NameRunes [32]uint16
72 NameLength uint16
73 Type DirType
74 Color Color
75 LeftChild int32
76 RightChild int32
77 StorageRoot int32
78 UID [16]byte
79 UserFlags uint32
80 CreateTime uint64
81 ModifyTime uint64
82 NextSector SecID
83 StreamSize uint32
84 _ uint32
85 }
86
87
88 func (e RawDirEnt) Name() string {
89 used := e.NameLength/2 - 1
90 if e.Type == DirEmpty || used > 32 {
91 return ""
92 }
93 return string(utf16.Decode(e.NameRunes[:used]))
94 }
95
96
97 type DirEnt struct {
98 RawDirEnt
99
100 Index int
101 name string
102 }
103
104
105 func (e DirEnt) Name() string {
106 return e.name
107 }
108
View as plain text