dump elf info
This commit is contained in:
parent
cabd4abe7f
commit
328703ac5f
@ -3,6 +3,6 @@ project(unflutter)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
add_executable(unflutter main.cpp dart/dart.h)
|
add_executable(unflutter main.cpp dart/dart.h dart/dart.cpp)
|
||||||
|
|
||||||
target_include_directories(unflutter PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty)
|
target_include_directories(unflutter PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty)
|
||||||
16
dart/dart.cpp
Normal file
16
dart/dart.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 26.11.22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "dart.h"
|
||||||
|
|
||||||
|
std::string snapshotKindString(SnapshotKind kind) {
|
||||||
|
switch (kind) {
|
||||||
|
case FULL: return "Full";
|
||||||
|
case FULL_JIT: return "Full JIT";
|
||||||
|
case FULL_AOT: return "Full AOT";
|
||||||
|
case MESSAGE: return "Message";
|
||||||
|
case NONE: return "None";
|
||||||
|
case INVALID: return "Invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
11
dart/dart.h
11
dart/dart.h
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
const int32_t DART_MAGIC = 0xdcdcf5f5;
|
const uint32_t DART_MAGIC = 0xDCDCF5F5;
|
||||||
|
|
||||||
enum class SnaphotKind: uint64_t {
|
enum SnapshotKind: uint64_t {
|
||||||
FULL,
|
FULL,
|
||||||
FULL_JIT,
|
FULL_JIT,
|
||||||
FULL_AOT,
|
FULL_AOT,
|
||||||
@ -23,9 +24,11 @@ enum class SnaphotKind: uint64_t {
|
|||||||
struct SnapshotHeader {
|
struct SnapshotHeader {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
SnaphotKind kind;
|
SnapshotKind kind;
|
||||||
std::array<char8_t, 32> versionHash;
|
std::array<char8_t, 32> versionHash;
|
||||||
};
|
};
|
||||||
#pragma pack (0)
|
#pragma pack ()
|
||||||
|
|
||||||
|
std::string snapshotKindString(SnapshotKind kind);
|
||||||
|
|
||||||
#endif //UNFLUTTER_DART_H
|
#endif //UNFLUTTER_DART_H
|
||||||
|
|||||||
54
main.cpp
54
main.cpp
@ -1,10 +1,13 @@
|
|||||||
#include "ThirdParty/elfio/elfio.hpp"
|
#include "ThirdParty/elfio/elfio.hpp"
|
||||||
#include "dart/dart.h"
|
#include "dart/dart.h"
|
||||||
|
#include "elfio/elfio_dump.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <elf.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::string elfPath = "/home/selim/Downloads/libapp.so"; //argv[1];
|
std::string elfPath = "/home/selim/Загрузки/libapp.so"; //argv[1];
|
||||||
std::cout << "Analyzing file: " << elfPath << std::endl;
|
std::cout << "Analyzing file: " << elfPath << std::endl;
|
||||||
|
|
||||||
ELFIO::elfio reader;
|
ELFIO::elfio reader;
|
||||||
@ -13,32 +16,71 @@ int main(int argc, char** argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* data = nullptr;
|
const std::byte* data = nullptr;
|
||||||
const void* text = nullptr;
|
const std::byte* text = nullptr;
|
||||||
|
|
||||||
ELFIO::Elf_Half sec_num = reader.sections.size();
|
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;
|
std::cout << "Number of sections: " << sec_num << std::endl;
|
||||||
for ( int i = 0; i < sec_num; ++i ) {
|
for ( int i = 0; i < sec_num; ++i ) {
|
||||||
const ELFIO::section* psec = reader.sections[i];
|
ELFIO::section* psec = reader.sections[i];
|
||||||
std::cout << " [" << i << "] "
|
std::cout << " [" << i << "] "
|
||||||
<< psec->get_name()
|
<< psec->get_name()
|
||||||
<< "\t"
|
<< "\t"
|
||||||
<< psec->get_size()
|
<< psec->get_size()
|
||||||
|
<< ", " << psec->get_type()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
if(psec->get_name() == ".rodata") {
|
if(psec->get_name() == ".rodata") {
|
||||||
data = psec->get_data();
|
data = reinterpret_cast<const std::byte*>(psec->get_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(psec->get_name() == ".text") {
|
if(psec->get_name() == ".text") {
|
||||||
text = psec->get_data();
|
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);
|
auto header = reinterpret_cast<const SnapshotHeader*>(data);
|
||||||
if(header->magic != DART_MAGIC) {
|
if(header->magic != DART_MAGIC) {
|
||||||
std::cout << "Wrong magic!!!!" << std::endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user