/
softrace.go
129 lines (111 loc) · 2.49 KB
/
softrace.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package softrace
import (
"github.com/boltdb/bolt"
"io"
"strings"
"time"
)
// RDSFile CSV file path
const RDSFilesPath = "data/nsrl_rds/rds_modern/NSRLFile.txt"
// RDSProd CSV file path
const RDSProductsPath = "data/nsrl_rds/rds_modern/NSRLProd.txt"
// RDSProd CSV file path
const RDSOpSystemsPath = "data/nsrl_rds/rds_modern/NSRLOS.txt"
// BoltDB path
const BoltPath = "data/bolt/bolt.db"
// Gin-gonic configuration
const GinConn = "0.0.0.0:8001"
//
type RDSFiles struct {
SHA1 string
MD5 string
CRC32 string
FileName string
FileSize string
ProductCode string
OpSystemCode string
SpecialCode string
}
//
type RDSProducts struct {
ProductCode string
ProductName string
ProductVersion string
OpSystemCode string
MfgCode string
Language string
ApplicationType string
}
//
type RDSOpSystems struct {
OpSystemCode string
OpSystemName string
OpSystemVersion string
MfgCode string
}
//
type RDS struct {
SHA1 string
MD5 string
CRC32 string
FileName string
FileSize string
ProductName string
ProductVersion string
ApplicationType string
OpSystemName string
OpSystemVersion string
}
//
type Index struct {
KeyType []byte
Key []byte
Encoded []byte
}
//
type Result struct {
SHA1 string `json:"sha1"`
MD5 string `json:"md5"`
CRC32 string `json:"crc32"`
FileName string `json:"file_name"`
FileSize string `json:"file_size"`
ProductName string `json:"product_name"`
ProductVersion string `json:"product_version"`
ApplicationType string `json:"application_type"`
OpSystemName string `json:"os_name"`
OpSystemVersion string `json:"os_version"`
}
//
type LookupInput struct {
HashUpper []byte
Length int
}
//
func (*RDS) MapToResponse(n *RDS) Result {
return Result{
SHA1: strings.ToLower(n.SHA1),
MD5: strings.ToLower(n.MD5),
CRC32: strings.ToLower(n.CRC32),
FileName: n.FileName,
FileSize: n.FileSize,
ProductName: n.ProductName,
ProductVersion: n.ProductVersion,
ApplicationType: n.ApplicationType,
OpSystemName: n.OpSystemName,
OpSystemVersion: n.OpSystemVersion,
}
}
//
func ConnectBolt() (*bolt.DB, error) {
db, err := bolt.Open(BoltPath, 0600, nil)
Check(err)
db.MaxBatchSize = 10000
db.MaxBatchDelay = 10 * time.Millisecond
return db, err
}
//
func Check(e error) {
if (e != nil) && (e != io.EOF) {
panic(e)
}
}