File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package bgheader
2+
3+ import (
4+ "encoding/binary"
5+ "fmt"
6+ "io"
7+ )
8+
9+ var (
10+ binaryOrder = binary .LittleEndian
11+ )
12+
13+ type structInfo struct {
14+ ID structureID `json:"StructInfoID"`
15+ Version uint8 `json:"StructInfoVersion"`
16+ }
17+
18+ type structureID [8 ]byte
19+
20+ type BootGuardVersion uint8
21+
22+ const (
23+ Version10 BootGuardVersion = 1
24+ Version20 BootGuardVersion = 2
25+ )
26+
27+ func (bgv BootGuardVersion ) String () string {
28+ switch bgv {
29+ case Version10 :
30+ return "1.0"
31+ case Version20 :
32+ return "2.0"
33+ }
34+ return "unknown"
35+ }
36+
37+ func DetectBGV (r io.Reader ) (BootGuardVersion , error ) {
38+ var s structInfo
39+ var bgv BootGuardVersion
40+
41+ err := binary .Read (r , binaryOrder , s .ID [:])
42+ if err != nil {
43+ return 0 , fmt .Errorf ("unable to read field 'ID': %w" , err )
44+ }
45+ err = binary .Read (r , binaryOrder , bgv )
46+ if err != nil {
47+ return 0 , fmt .Errorf ("unable to read field 'Version': %w" , err )
48+ }
49+
50+ return bgv , nil
51+ }
You can’t perform that action at this time.
0 commit comments