in pe.go [106:144]
func (f *peFile) goSymbols(stdlib bool) ([]string, error) {
tab, err := f.pclnTable()
if err != nil {
return nil, err
}
imports := make([]string, 0, len(f.objFile.Symbols))
for _, sym := range f.objFile.Symbols {
// https://wiki.osdev.org/COFF#Symbol_Table
const (
N_UNDEF = 0
N_ABS = -1
N_DEBUG = -2
)
switch sym.SectionNumber {
case N_UNDEF, N_ABS, N_DEBUG:
continue
}
if sym.SectionNumber < 0 || len(f.objFile.Sections) < int(sym.SectionNumber) {
return nil, fmt.Errorf("invalid section number in symbol table")
}
const STYP_TEXT = 0x20 // https://wiki.osdev.org/COFF#Section_Header
if f.objFile.Sections[sym.SectionNumber-1].Characteristics&STYP_TEXT == 0 {
continue
}
if strings.HasPrefix(sym.Name, "type..") {
continue
}
if !stdlib && isStdlib(sym.Name, uint64(sym.Value), tab) {
continue
}
imports = append(imports, sym.Name)
}
if len(imports) == 0 {
imports = nil
}
return imports, nil
}