87 lines
3.0 KiB
C++
87 lines
3.0 KiB
C++
#include "ThirdParty/elfio/elfio.hpp"
|
|
#include "dart/dart.h"
|
|
#include "elfio/elfio_dump.hpp"
|
|
|
|
#include <iostream>
|
|
#include <cstddef>
|
|
#include <elf.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
std::string elfPath = "/home/selim/Загрузки/libapp.so"; //argv[1];
|
|
std::cout << "Analyzing file: " << elfPath << std::endl;
|
|
|
|
ELFIO::elfio reader;
|
|
if(!reader.load(elfPath)) {
|
|
std::cout << "error loading elf: " << elfPath << std::endl;
|
|
return 0;
|
|
}
|
|
|
|
const std::byte* data = nullptr;
|
|
const std::byte* text = nullptr;
|
|
|
|
ELFIO::Elf_Half sec_num = reader.sections.size();
|
|
|
|
ELFIO::dump::header( std::cout, reader );
|
|
ELFIO::dump::section_headers( std::cout, reader );
|
|
ELFIO::dump::segment_headers( std::cout, reader );
|
|
ELFIO::dump::symbol_tables( std::cout, reader );
|
|
ELFIO::dump::notes( std::cout, reader );
|
|
ELFIO::dump::modinfo( std::cout, reader );
|
|
ELFIO::dump::dynamic_tags( std::cout, reader );
|
|
ELFIO::dump::section_datas( std::cout, reader );
|
|
ELFIO::dump::segment_datas( std::cout, reader );
|
|
|
|
std::cout << "Number of sections: " << sec_num << std::endl;
|
|
for ( int i = 0; i < sec_num; ++i ) {
|
|
ELFIO::section* psec = reader.sections[i];
|
|
std::cout << " [" << i << "] "
|
|
<< psec->get_name()
|
|
<< "\t"
|
|
<< psec->get_size()
|
|
<< ", " << psec->get_type()
|
|
<< std::endl;
|
|
|
|
if(psec->get_name() == ".rodata") {
|
|
data = reinterpret_cast<const std::byte*>(psec->get_data());
|
|
}
|
|
|
|
if(psec->get_name() == ".text") {
|
|
text = reinterpret_cast<const std::byte*>(psec->get_data());
|
|
}
|
|
|
|
auto sectionType = psec->get_type();
|
|
if(sectionType == SHT_SYMTAB || sectionType == SHT_DYNSYM) {
|
|
const ELFIO::symbol_section_accessor symbols( reader, psec );
|
|
for ( unsigned int j = 0; j < symbols.get_symbols_num(); ++j ) {
|
|
std::string name;
|
|
Elf64_Addr value;
|
|
ELFIO::Elf_Xword size;
|
|
unsigned char bind;
|
|
unsigned char type;
|
|
ELFIO::Elf_Half section_index;
|
|
unsigned char other;
|
|
symbols.get_symbol( j, name, value, size, bind,
|
|
type, section_index, other );
|
|
std::cout << j << " " << name << " " << value << " (section " << section_index << ")" << std::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::cout << "====================================================" << std::endl;
|
|
std::cout << "===== .rodata ======================================" << std::endl;
|
|
std::cout << std::endl;
|
|
|
|
auto header = reinterpret_cast<const SnapshotHeader*>(data);
|
|
if(header->magic != DART_MAGIC) {
|
|
std::cout << "Wrong magic!!!!" << std::endl;
|
|
}
|
|
|
|
std::cout << "Snapshot kind: " << snapshotKindString(header->kind) << std::endl;
|
|
std::cout << "Size: " << header->size << std::endl;
|
|
std::cout << std::endl;
|
|
|
|
auto ptr = data + header->size + 4;
|
|
|
|
return 0;
|
|
}
|