Skip to content

Commit c9b8b45

Browse files
committed
Adding Exports() for Elf.
1 parent 1724e0c commit c9b8b45

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

elf/exports.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package elf
2+
3+
/*
4+
Any symbol in the dynamic symbol table (in .dynsym) for which .st_shndx == SHN_UNDEF
5+
(references undefined section) is an import, and every other symbol is defined and exported.
6+
*/
7+
8+
// Export - describes a single export entry
9+
type Export struct {
10+
Name string
11+
VirtualAddress uint64
12+
}
13+
14+
// Exports - gets exports
15+
func (f *File) Exports() ([]Export, error) {
16+
17+
var exports []Export
18+
symbols, err := f.DynamicSymbols()
19+
if err != nil {
20+
return nil, err
21+
}
22+
for _, s := range symbols {
23+
if s.Section != SHN_UNDEF {
24+
exports = append(exports, Export{
25+
Name: s.Name,
26+
VirtualAddress: s.Value,
27+
})
28+
}
29+
}
30+
31+
return exports, nil
32+
}

0 commit comments

Comments
 (0)