// The shared library contains a note containing the ABI hash that is mapped into // memory and there is a local symbol called go.link.abihashbytes that points 16 // bytes into it. func testABIHashNote(t *testing.T, f *elf.File, note *note) { if note.section.Flags != elf.SHF_ALLOC { t.Errorf("abi hash section has flags %v", note.section.Flags) } if !isOffsetLoaded(f, note.section.Offset) { t.Errorf("abihash section not contained in PT_LOAD segment") } var hashbytes elf.Symbol symbols, err := f.Symbols() if err != nil { t.Errorf("error reading symbols %v", err) return } for _, sym := range symbols { if sym.Name == "go.link.abihashbytes" { hashbytes = sym } } if hashbytes.Name == "" { t.Errorf("no symbol called go.link.abihashbytes") return } if elf.ST_BIND(hashbytes.Info) != elf.STB_LOCAL { t.Errorf("%s has incorrect binding %v", hashbytes.Name, elf.ST_BIND(hashbytes.Info)) } if f.Sections[hashbytes.Section] != note.section { t.Errorf("%s has incorrect section %v", hashbytes.Name, f.Sections[hashbytes.Section].Name) } if hashbytes.Value-note.section.Addr != 16 { t.Errorf("%s has incorrect offset into section %d", hashbytes.Name, hashbytes.Value-note.section.Addr) } }
func printFileInformation(f *elf.File) { printHeader(&f.FileHeader) printSections(f.Sections) printProgs(f.Progs) printImportedLibraries(f.ImportedLibraries()) printSymbols(f.Symbols()) printImportedSymbols(f.ImportedSymbols()) }
func dump_symbols(file *elf.File) { fmt.Printf("Symbols:\n") symbols, _ := file.Symbols() for _, e := range symbols { if !strings.EqualFold(e.Name, "") { fmt.Printf("\t%s\n", e.Name) } } }
func GetSymbols(e *elf.File) map[ds.Range]*ds.Symbol { res := make(map[ds.Range]*ds.Symbol) symbols, err := e.Symbols() if err != nil { log.WithFields(log.Fields{"error": err}).Info("Failed to Parse Symbols") return res } for _, sym := range symbols { sym_type := elfSymbolTypeToSymbolType(uint(sym.Info)) symbol := ds.NewSymbol(sym.Name, sym_type) res[ds.NewRange(sym.Value, sym.Value+sym.Size)] = symbol } return res }
func canary(file *elf.File) string { if symbols, e := file.Symbols(); e == nil { for _, sym := range symbols { if bytes.HasPrefix([]byte(sym.Name), []byte(STACK_CHK)) { return ENABLED } } } if importedSymbols, e := file.ImportedSymbols(); e == nil { for _, imp := range importedSymbols { if bytes.HasPrefix([]byte(imp.Name), []byte(STACK_CHK)) { return ENABLED } } } return DISABLED }