forked from saferwall/elf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
54 lines (50 loc) · 1.11 KB
/
json.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
package elf
import (
"encoding/json"
"errors"
"strings"
)
// DumpRawJSON marshals the raw binary representation into JSON Format.
func (p *Parser) DumpRawJSON() (string, error) {
var jsonOutput strings.Builder
switch p.F.Class() {
case ELFCLASS32:
jsonBin, err := json.MarshalIndent(p.F.ELFBin32, "", " ")
if err != nil {
return "", err
}
jsonSymbols, err := json.MarshalIndent(p.F.ELFSymbols, "", " ")
if err != nil {
return "", err
}
_, err = jsonOutput.Write(jsonBin)
if err != nil {
return "", err
}
_, err = jsonOutput.Write(jsonSymbols)
if err != nil {
return "", err
}
return jsonOutput.String(), nil
case ELFCLASS64:
jsonBin, err := json.MarshalIndent(p.F.ELFBin64, "", " ")
if err != nil {
return "", err
}
jsonSymbols, err := json.MarshalIndent(p.F.ELFSymbols, "", " ")
if err != nil {
return "", err
}
_, err = jsonOutput.Write(jsonBin)
if err != nil {
return "", err
}
_, err = jsonOutput.Write(jsonSymbols)
if err != nil {
return "", err
}
return jsonOutput.String(), nil
default:
return "", errors.New("unsupported ELF Class")
}
}