From 6e9f0f5dfe04ed1abc75119027d031c934accc34 Mon Sep 17 00:00:00 2001 From: Gaulthier Gain Date: Mon, 6 Dec 2021 20:07:29 +0100 Subject: [PATCH] Add map to manager functions names and addresses --- srcs/binarytool/elf64core/elf_file.go | 1 + srcs/binarytool/elf64core/elf_function.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/srcs/binarytool/elf64core/elf_file.go b/srcs/binarytool/elf64core/elf_file.go index d3cccbe..955544c 100644 --- a/srcs/binarytool/elf64core/elf_file.go +++ b/srcs/binarytool/elf64core/elf_file.go @@ -23,6 +23,7 @@ type ELF64File struct { FunctionsTables []FunctionTables Raw []byte IndexSections map[string]int + MapFctAddrName map[uint64]string Name string Endianness binary.ByteOrder TextSectionIndex []int // slice since we can have several diff --git a/srcs/binarytool/elf64core/elf_function.go b/srcs/binarytool/elf64core/elf_function.go index f7d9504..eda4693 100644 --- a/srcs/binarytool/elf64core/elf_function.go +++ b/srcs/binarytool/elf64core/elf_function.go @@ -24,9 +24,9 @@ type FunctionTables struct { } type ELF64Function struct { - Name string - Addr uint64 - Size uint64 + Name string + Addr uint64 + Size uint64 } func (elfFile *ELF64File) getIndexFctTable(ndx uint16) int { @@ -58,7 +58,15 @@ func (elfFile *ELF64File) detectSizeSymbol(symbolsTable []ELF64Function, index i func (elfFile *ELF64File) inspectFunctions() error { + nbEntries := 0 for _, table := range elfFile.SymbolsTables { + nbEntries += table.nbEntries + } + + elfFile.MapFctAddrName = make(map[uint64]string, nbEntries) + + for _, table := range elfFile.SymbolsTables { + for _, s := range table.dataSymbols { k := elfFile.getIndexFctTable(s.elf64sym.Shndx) if k != -1 && s.elf64sym.Value > 0 { @@ -75,6 +83,7 @@ func (elfFile *ELF64File) inspectFunctions() error { elfFile.FunctionsTables[k].Functions = append(elfFile.FunctionsTables[k].Functions, function) } + elfFile.MapFctAddrName[s.elf64sym.Value] = s.name } }