unflutter/main.cpp
2022-11-27 12:49:38 +03:00

87 lines
2.9 KiB
C++

#include "ThirdParty/elfio/elfio.hpp"
#include "dart/dart.h"
#include "elfio/elfio_dump.hpp"
#include <iostream>
#include <cstddef>
#include <elf.h>
void dumpElf(const ELFIO::elfio& reader) {
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 );
}
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;
}
dumpElf(reader);
const std::byte* data = nullptr;
const std::byte* text = nullptr;
for(auto section: reader.sections) {
}
ELFIO::Elf_Half sec_num = reader.sections.size();
for ( int i = 0; i < sec_num; ++i ) {
ELFIO::section* psec = reader.sections[i];
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;
}