-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.go
59 lines (52 loc) · 1.24 KB
/
entry.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
package ldcache
import (
"encoding/binary"
"fmt"
"io"
"unsafe"
)
var entryLength = unsafe.Sizeof(rawEntry{})
// Entry represents an entry in a ld.so.cache file
type Entry struct {
Flags Flags
Key, Value string
OSVersion uint32
HWCap uint64
keyPos uint32
valuePos uint32
}
type rawEntry struct {
Flags Flags
Key, Value uint32
OSVersion uint32
HWCap uint64
}
func readEntry(order binary.ByteOrder, in io.Reader) (*Entry, error) {
// read a single entry from a stream
e := &rawEntry{}
err := binary.Read(in, order, e)
if err != nil {
return nil, err
}
entry := &Entry{
Flags: e.Flags,
keyPos: e.Key,
valuePos: e.Value,
OSVersion: e.OSVersion,
HWCap: e.HWCap,
}
return entry, nil
}
// Bytes return the entry as it would appear in a file, as binary format
func (e *Entry) Bytes(order binary.ByteOrder) []byte {
buf := make([]byte, 24)
order.PutUint32(buf[:4], uint32(e.Flags))
order.PutUint32(buf[4:8], e.keyPos)
order.PutUint32(buf[8:12], e.valuePos)
order.PutUint32(buf[12:16], e.OSVersion)
order.PutUint64(buf[16:24], e.HWCap)
return buf
}
func (e *Entry) String() string {
return fmt.Sprintf("%s (%s) => %s (OSVersion=%d HWCap=%d)", e.Key, e.Flags, e.Value, e.OSVersion, e.HWCap)
}