summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2024-09-18 16:41:09 -0400
committerJosh Ferrell <josh@vector35.com>2024-09-18 16:41:09 -0400
commitafb41a37f9f6fa9e3c2d8df35fa9c9ae215299ee (patch)
tree5506dc268f98ba3083fdc5098ba3a4d37fde1e0b
parenta4b2f1ed627c2cc7aa6c09dac8390ebce2147d7b (diff)
Add support for loading symbols from .gnu_debugdata
-rw-r--r--view/elf/elfview.cpp40
-rw-r--r--view/elf/elfview.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp
index 677f0b67..b90b18a7 100644
--- a/view/elf/elfview.cpp
+++ b/view/elf/elfview.cpp
@@ -1325,6 +1325,8 @@ bool ElfView::Init()
}
}
+ ParseMiniDebugInfo();
+
// Process the queued symbols
m_symbolQueue->Process();
delete m_symbolQueue;
@@ -2608,6 +2610,44 @@ bool ElfView::DerefPpc64Descriptor(BinaryReader& reader, uint64_t addr, uint64_t
}
+void ElfView::ParseMiniDebugInfo()
+{
+ Ref<Section> gnuDebugdata = GetParentView()->GetSectionByName(".gnu_debugdata");
+ if (!gnuDebugdata)
+ return;
+
+ BinaryReader debugdataReader(GetParentView());
+ debugdataReader.Seek(gnuDebugdata->GetStart());
+
+ DataBuffer compressedDebug = debugdataReader.Read(gnuDebugdata->GetLength());
+
+ DataBuffer debugElf;
+ if (!compressedDebug.XzDecompress(debugElf))
+ {
+ m_logger->LogError("Invalid .gnu_debugdata contents: Failed to decompress");
+ return;
+ }
+
+ Ref<BinaryView> debugBv = Load(debugElf, false);
+ if (!debugBv)
+ {
+ m_logger->LogError("Invalid .gnu_debugdata contents: Failed to create BinaryView");
+ return;
+ }
+
+ for (const auto& symbol : debugBv->GetSymbols())
+ {
+ DefineElfSymbol(
+ symbol->GetType(),
+ symbol->GetRawName(),
+ GetStart() + symbol->GetAddress(),
+ false,
+ symbol->GetBinding()
+ );
+ }
+}
+
+
vector<ElfSymbolTableEntry> ElfView::ParseSymbolTable(BinaryReader& reader, const Elf64SectionHeader& symbolSection,
const Elf64SectionHeader& stringSection, bool dynamic, size_t startEntry)
{
diff --git a/view/elf/elfview.h b/view/elf/elfview.h
index 856dacbd..23a5021a 100644
--- a/view/elf/elfview.h
+++ b/view/elf/elfview.h
@@ -538,6 +538,8 @@ namespace BinaryNinja
void GetRelocEntries(BinaryReader& reader, const std::vector<Elf64SectionHeader>& sections,
bool implicit, std::vector<ELFRelocEntry>& result);
bool DerefPpc64Descriptor(BinaryReader& reader, uint64_t addr, uint64_t& result);
+
+ void ParseMiniDebugInfo();
public:
ElfView(BinaryView* data, bool parseOnly = false);
~ElfView();