-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse.go
74 lines (59 loc) · 1.93 KB
/
parse.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
/*
Copyright © 2020 iiusky [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package WappalyzerParse
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
)
type WappalyzerParse struct {
Filename string // 指纹库路径,如果不指定,则使用默认内置路径
IsDebug bool // 开启后将直接打印出错误信息
Fingerprints []Fingerprint // 指纹库结果
}
// 获取wappalyzer指纹库的结果,返回包装好的结构体类型
func (w *WappalyzerParse) InitFingerPrintData() {
var dataJson map[string]interface{}
var dataByte []byte
var err error
if w.Filename == "" {
w.Filename = "technologies.json"
}
dataByte, err = ioutil.ReadFile(w.Filename)
if err != nil {
if w.IsDebug {
fmt.Printf("open file err: %v \n", err)
}
return
}
err = json.Unmarshal(dataByte, &dataJson)
if err != nil {
if w.IsDebug {
fmt.Printf("json unmarshal err: %v \n", err)
}
return
}
categories := categoriesExtractor(dataJson["categories"])
technologies := technologiesExtractor(dataJson["technologies"])
w.Fingerprints = outputData(technologies, categories)
}
// 输出格式转为json,涉及到json序列化后html标签实体化问题,通过自定义json.encoder解决
func (w *WappalyzerParse) FormatJson() string {
bf := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(bf)
jsonEncoder.SetEscapeHTML(false)
jsonEncoder.SetIndent("", " ")
_ = jsonEncoder.Encode(w.Fingerprints)
return bf.String()
}