From 726e349092a71d13b442ad2c9521716bd4496894 Mon Sep 17 00:00:00 2001 From: Gaulthier Gain Date: Mon, 6 Dec 2021 20:13:18 +0100 Subject: [PATCH] Export pageSize and consider "ld.o" files --- srcs/binarytool/elf64analyser/elf_analyser.go | 10 +++++----- srcs/binarytool/elf64analyser/elf_pages.go | 2 +- srcs/binarytool/elf64analyser/elf_stats.go | 6 +++--- srcs/binarytool/run_binarytool.go | 2 +- srcs/binarytool/unikernels.go | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/srcs/binarytool/elf64analyser/elf_analyser.go b/srcs/binarytool/elf64analyser/elf_analyser.go index 61a656e..78ad0ad 100644 --- a/srcs/binarytool/elf64analyser/elf_analyser.go +++ b/srcs/binarytool/elf64analyser/elf_analyser.go @@ -52,8 +52,8 @@ func (analyser *ElfAnalyser) DisplayMapping() { _, _ = fmt.Fprintf(w, "%s \t0x%x \t0x%x \t0x%x\t%d\t%f\t%f\n", name, lib.StartAddr, lib.EndAddr, lib.Size, - lib.NbSymbols, float32(lib.Size)/float32(pageSize), - float32(lib.StartAddr)/float32(pageSize)) + lib.NbSymbols, float32(lib.Size)/float32(PageSize), + float32(lib.StartAddr)/float32(PageSize)) } _ = w.Flush() } @@ -222,7 +222,7 @@ func (analyser *ElfAnalyser) SplitIntoPagesBySection(elfFile *elf64core.ELF64Fil } func CreateNewPage(startAddress uint64, k int, raw []byte) *ElfPage { - byteArray := make([]byte, pageSize) + byteArray := make([]byte, PageSize) b := raw if cpd := copy(byteArray, b); cpd == 0 { u.PrintWarning("0 bytes were copied") @@ -241,9 +241,9 @@ func CreateNewPage(startAddress uint64, k int, raw []byte) *ElfPage { func (analyser *ElfAnalyser) computePage(elfFile *elf64core.ELF64File, section string, indexSection int) { offsetTextSection := elfFile.SectionsTable.DataSect[indexSection].Elf64section.FileOffset k := 0 - for i := offsetTextSection; i < offsetTextSection+elfFile.SectionsTable.DataSect[indexSection].Elf64section.Size; i += pageSize { + for i := offsetTextSection; i < offsetTextSection+elfFile.SectionsTable.DataSect[indexSection].Elf64section.Size; i += PageSize { - end := i + pageSize + end := i + PageSize if end >= uint64(len(elfFile.Raw)) { end = uint64(len(elfFile.Raw) - 1) } diff --git a/srcs/binarytool/elf64analyser/elf_pages.go b/srcs/binarytool/elf64analyser/elf_pages.go index 7178740..5bd0951 100644 --- a/srcs/binarytool/elf64analyser/elf_pages.go +++ b/srcs/binarytool/elf64analyser/elf_pages.go @@ -13,7 +13,7 @@ import ( "strings" ) -const pageSize = 0x1000 +const PageSize = 0x1000 type ElfFileSegment struct { Filename string diff --git a/srcs/binarytool/elf64analyser/elf_stats.go b/srcs/binarytool/elf64analyser/elf_stats.go index d626b88..5412746 100644 --- a/srcs/binarytool/elf64analyser/elf_stats.go +++ b/srcs/binarytool/elf64analyser/elf_stats.go @@ -242,7 +242,7 @@ func (analyser *ElfAnalyser) DisplayStatSize(elfFile *elf64core.ELF64File) { size = s.Elf64section.Size totalSizeText += size } - _, _ = fmt.Fprintf(w, "%s\t%d (0x%x)\t%.2f\t%s\n", s.Name, size, size, float32(size)/float32(pageSize), currNext) + _, _ = fmt.Fprintf(w, "%s\t%d (0x%x)\t%.2f\t%s\n", s.Name, size, size, float32(size)/float32(PageSize), currNext) } } @@ -250,8 +250,8 @@ func (analyser *ElfAnalyser) DisplayStatSize(elfFile *elf64core.ELF64File) { _, _ = fmt.Fprintf(w, "Total Size:\n") _, _ = fmt.Fprintf(w, "Section .text:\t%d (0x%x)\n", totalSizeText, totalSizeText) _, _ = fmt.Fprintf(w, "All sections:\t%d (0x%x)\n", totalSizeElf, totalSizeElf) - _, _ = fmt.Fprintf(w, "#Pages (.text):\t%d\n", roundPage(float64(totalSizeText)/float64(pageSize))) - _, _ = fmt.Fprintf(w, "#Pages (all sections):\t%d\n", roundPage(float64(totalSizeElf)/float64(pageSize))) + _, _ = fmt.Fprintf(w, "#Pages (.text):\t%d\n", roundPage(float64(totalSizeText)/float64(PageSize))) + _, _ = fmt.Fprintf(w, "#Pages (all sections):\t%d\n", roundPage(float64(totalSizeElf)/float64(PageSize))) _ = w.Flush() } diff --git a/srcs/binarytool/run_binarytool.go b/srcs/binarytool/run_binarytool.go index eed9d05..0d6b230 100644 --- a/srcs/binarytool/run_binarytool.go +++ b/srcs/binarytool/run_binarytool.go @@ -113,7 +113,7 @@ func RunBinaryAnalyser(homeDir string) { } } - if foundSection { + if foundSection && len(uk.SectionSplit) > 0 { path := homeDir + u.SEP + pagesPath if _, err := os.Stat(path); os.IsNotExist(err) { diff --git a/srcs/binarytool/unikernels.go b/srcs/binarytool/unikernels.go index 63f8511..ccd16a3 100644 --- a/srcs/binarytool/unikernels.go +++ b/srcs/binarytool/unikernels.go @@ -73,11 +73,11 @@ func (uk *Unikernel) GetFiles() error { for _, f := range files { if f.IsDir() || strings.Contains(f.Name(), makefile) || - strings.Contains(f.Name(), config) || - strings.Contains(f.Name(), ldExt) { + strings.Contains(f.Name(), config) { continue } - if filepath.Ext(strings.TrimSpace(f.Name())) == objExt && + + if strings.Contains(f.Name(), ldExt) && !stringInSlice(f.Name(), uk.IgnoredPlats) { objFile, err := parseFile(uk.BuildPath, f.Name()) if err != nil {