-
Notifications
You must be signed in to change notification settings - Fork 22
/
struct.go
77 lines (64 loc) · 2 KB
/
struct.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
76
77
package sploit
import (
"encoding/binary"
)
// PackUint64LE packs a uint64 into a byte slice in little endian format
func PackUint64LE(i uint64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, i)
return b
}
// PackUint32LE packs a uint32 into a byte slice in little endian format
func PackUint32LE(i uint32) []byte {
b := make([]byte, 4)
binary.LittleEndian.PutUint32(b, i)
return b
}
// PackUint16LE packs a uint16 into a byte slice in little endian format
func PackUint16LE(i uint16) []byte {
b := make([]byte, 2)
binary.LittleEndian.PutUint16(b, i)
return b
}
// PackUint64BE packs a uint64 into a byte slice in big endian format
func PackUint64BE(i uint64) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, i)
return b
}
// PackUint32BE packs a uint32 into a byte slice in big endian format
func PackUint32BE(i uint32) []byte {
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, i)
return b
}
// PackUint16BE packs a uint16 into a byte slice in big endian format
func PackUint16BE(i uint16) []byte {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, i)
return b
}
// UnpackUint64LE unpacks a byte slice in little endian format into a uint64
func UnpackUint64LE(b []byte) uint64 {
return binary.LittleEndian.Uint64(b)
}
// UnpackUint32LE unpacks a byte slice in little endian format into a uint32
func UnpackUint32LE(b []byte) uint32 {
return binary.LittleEndian.Uint32(b)
}
// UnpackUint16LE unpacks a byte slice in little endian format into a uint16
func UnpackUint16LE(b []byte) uint16 {
return binary.LittleEndian.Uint16(b)
}
// UnpackUint64BE unpacks a byte slice in big endian format into a uint64
func UnpackUint64BE(b []byte) uint64 {
return binary.BigEndian.Uint64(b)
}
// UnpackUint32BE unpacks a byte slice in big endian format into a uint32
func UnpackUint32BE(b []byte) uint32 {
return binary.BigEndian.Uint32(b)
}
// UnpackUint16BE unpacks a byte slice in big endian format into a uint16
func UnpackUint16BE(b []byte) uint16 {
return binary.BigEndian.Uint16(b)
}