MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / ElfView

Method ElfView

view/elf/elfview.cpp:46–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45
46ElfView::ElfView(BinaryView* data, bool parseOnly): BinaryView("ELF", data->GetFile(), data), m_parseOnly(parseOnly)
47{
48 Elf64Header header;
49 string errorMsg;
50 BNEndianness endian;
51 if (!g_elfViewType->ParseHeaders(data, m_ident, m_commonHeader, header, &m_arch, &m_plat, errorMsg, endian))
52 throw ElfFormatException(errorMsg);
53
54 CreateLogger("BinaryView");
55 m_logger = CreateLogger("BinaryView.ElfView");
56 m_elf32 = m_ident.fileClass == 1;
57 m_addressSize = (m_ident.fileClass == 1) ? 4 : 8;
58 m_endian = endian;
59 m_relocatable = m_commonHeader.type == ET_DYN || m_commonHeader.type == ET_REL;
60 m_objectFile = m_commonHeader.type == ET_REL;
61 m_backedByDatabase = data->GetFile()->IsBackedByDatabase("ELF");
62
63 memset(&m_symbolTableSection, 0, sizeof(m_symbolTableSection));
64 memset(&m_dynamicSymbolTableSection, 0, sizeof(m_dynamicSymbolTableSection));
65 memset(&m_dynamicStringTable, 0, sizeof(m_dynamicStringTable));
66 memset(&m_dynamicTable, 0, sizeof(m_dynamicTable));
67 memset(&m_relocSection, 0, sizeof(m_relocSection));
68 memset(&m_relocaSection, 0, sizeof(m_relocaSection));
69 memset(&m_tlsSegment, 0, sizeof(m_tlsSegment));
70 memset(&m_auxSymbolTable, 0, sizeof(m_auxSymbolTable));
71 memset(&m_sectionStringTable, 0, sizeof(m_sectionStringTable));
72 memset(&m_sectionOpd, 0, sizeof(m_sectionOpd));
73
74 m_logger->LogInfo("Detected %s endian ELF", m_endian == LittleEndian ? "Little Endian" : "Big Endian");
75
76
77 if (m_elf32 && (header.sectionHeaderSize != sizeof(Elf32SectionHeader)))
78 {
79 m_logger->LogWarn(
80 "The section header size reported by e_shentsize (0x%lx) is different from the size of Elf32_Shdr (0x%lx). "
81 "The parsing proceeds with the size of Elf32_Shdr.",
82 header.sectionHeaderSize, sizeof(Elf32SectionHeader));
83 header.sectionHeaderSize = sizeof(Elf32SectionHeader);
84 }
85 else if (!m_elf32 && (header.sectionHeaderSize != sizeof(Elf64SectionHeader)))
86 {
87 m_logger->LogWarn(
88 "The section header size reported by e_shentsize (0x%lx) is different from the size of Elf64_Shdr (0x%lx). "
89 "The parsing proceeds with the size of Elf64_Shdr.",
90 header.sectionHeaderSize, sizeof(Elf64SectionHeader));
91 header.sectionHeaderSize = sizeof(Elf64SectionHeader);
92 }
93
94 if (m_elf32 && (header.programHeaderSize != sizeof(Elf32ProgramHeader)))
95 {
96 m_logger->LogWarn(
97 "The program header size reported by e_phentsize (0x%lx) is different from the size of Elf32_Phdr (0x%lx). "
98 "The parsing proceeds with the size of Elf32_Phdr.",
99 header.programHeaderSize, sizeof(Elf32ProgramHeader));
100 header.programHeaderSize = sizeof(Elf32ProgramHeader);
101 }
102 else if (!m_elf32 && (header.programHeaderSize != sizeof(Elf64ProgramHeader)))
103 {

Callers

nothing calls this directly

Calls 15

ElfFormatExceptionClass · 0.85
IsBackedByDatabaseMethod · 0.80
LogInfoMethod · 0.80
LogWarnMethod · 0.80
LogDebugMethod · 0.80
push_backMethod · 0.80
LogErrorMethod · 0.80
c_strMethod · 0.80
GetFileMethod · 0.45
ParseHeadersMethod · 0.45
GetLengthMethod · 0.45
SetEndiannessMethod · 0.45

Tested by

no test coverage detected