-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf.go
35 lines (29 loc) · 798 Bytes
/
elf.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
package arch
import (
"context"
"debug/elf"
"go.uber.org/zap"
)
// ReadFuncSymbolNames reads the function symbols from the given binary file.
func ReadFuncSymbolNames(ctx context.Context, logger *zap.Logger, binPath string) ([]string, error) {
f, err := elf.Open(binPath)
if err != nil {
logger.Error("unable to open bin file", zap.Error(err))
return nil, err
}
defer f.Close()
symbols, err := f.Symbols()
if err != nil {
logger.Error("unable to read symbols", zap.Error(err))
return nil, err
}
names := make([]string, 0)
for _, symbol := range symbols {
if symbol.Info != byte(elf.STT_FUNC) {
continue
}
names = append(names, symbol.Name)
}
logger.Debug("read function symbol names", zap.Int("n", len(names)), zap.String("path", binPath))
return names, nil
}