-
Notifications
You must be signed in to change notification settings - Fork 3
/
manifest.go
90 lines (74 loc) · 2.14 KB
/
manifest.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
package pelican
import (
"encoding/json"
"github.com/pkg/errors"
)
type node = map[string]interface{}
func visit(n node, key string, f func(c node)) {
if c, ok := n[key].(node); ok {
f(c)
}
}
func visitMany(n node, key string, f func(c node)) {
if cs, ok := n[key].([]node); ok {
for _, c := range cs {
f(c)
}
}
if c, ok := n[key].(node); ok {
f(c)
}
}
func getString(n node, key string, f func(s string)) {
if s, ok := n[key].(string); ok {
f(s)
}
}
func interpretManifest(info *PeInfo, manifest []byte) error {
intermediate := make(node)
err := json.Unmarshal([]byte(manifest), &intermediate)
if err != nil {
return errors.WithStack(err)
}
assInfo := &AssemblyInfo{}
interpretIdentity := func(id node, f func(id *AssemblyIdentity)) {
ai := &AssemblyIdentity{}
getString(id, "-name", func(s string) { ai.Name = s })
getString(id, "-version", func(s string) { ai.Version = s })
getString(id, "-type", func(s string) { ai.Type = s })
getString(id, "-processorArchitecture", func(s string) { ai.ProcessorArchitecture = s })
getString(id, "-publicKeyToken", func(s string) { ai.PublicKeyToken = s })
getString(id, "-language", func(s string) { ai.Language = s })
f(ai)
}
visit(intermediate, "assembly", func(assembly node) {
visit(assembly, "assemblyIdentity", func(id node) {
interpretIdentity(id, func(ai *AssemblyIdentity) {
assInfo.Identity = ai
})
})
getString(assembly, "description", func(s string) { assInfo.Description = s })
visit(assembly, "trustInfo", func(ti node) {
visit(ti, "security", func(sec node) {
visit(sec, "requestedPrivileges", func(rp node) {
visit(rp, "requestedExecutionLevel", func(rel node) {
getString(rel, "-level", func(s string) {
assInfo.RequestedExecutionLevel = s
})
})
})
})
})
visit(assembly, "dependency", func(dep node) {
visitMany(dep, "dependentAssembly", func(da node) {
visit(da, "assemblyIdentity", func(id node) {
interpretIdentity(id, func(ai *AssemblyIdentity) {
info.DependentAssemblies = append(info.DependentAssemblies, ai)
})
})
})
})
})
info.AssemblyInfo = assInfo
return nil
}