项目作者: finixbit

项目描述 :
Lightweight elf binary parser with no external dependencies - Sections, Symbols, Relocations, Segments
高级语言: C++
项目地址: git://github.com/finixbit/elf-parser.git
创建时间: 2018-02-12T21:47:00Z
项目社区:https://github.com/finixbit/elf-parser

开源协议:MIT License

下载


elf-parser

Lightweight elf binary parser with no external dependencies - Sections, Symbols, Relocations, Segments

Required libraries

No dependencies

Usage

Sections (readelf -S executable)

parse sections header table from elf binary and return vector of section_t below

  1. typedef struct {
  2. int section_index = 0;
  3. std::intptr_t section_offset, section_addr;
  4. std::string section_name;
  5. std::string section_type;
  6. int section_size, section_ent_size, section_addr_align;
  7. } section_t;

get elf sections using elf-parser

  1. #include <elf-parser.h>
  2. elf_parser::Elf_parser elf_parser(executable_path);
  3. std::vector<elf_parser::section_t> secs = elf_parser.get_sections();

see example

Segments (readelf -l executable)

parse program header table from elf binary and return vector of segment_t below

  1. typedef struct {
  2. std::string segment_type, segment_flags;
  3. long segment_offset, segment_virtaddr, segment_physaddr, segment_filesize, segment_memsize;
  4. int segment_align;
  5. } segment_t;

get elf segments using elf-parser

  1. #include <elf-parser.h>
  2. elf_parser::Elf_parser elf_parser(executable_path);
  3. std::vector<elf_parser::segment_t> segs = elf_parser.get_segments();

see example

Symbols (readelf -s executable)

parse symbols table from elf binary and return vector of symbol_t below

  1. typedef struct {
  2. std::string symbol_index;
  3. std::intptr_t symbol_value;
  4. int symbol_num = 0, symbol_size = 0;
  5. std::string symbol_type, symbol_bind, symbol_visibility, symbol_name, symbol_section;
  6. } symbol_t;

get elf symbols using elf-parser

  1. #include <elf-parser.h>
  2. elf_parser::Elf_parser elf_parser(executable_path);
  3. std::vector<elf_parser::symbol_t> syms = elf_parser.get_symbols();

see example

Relocations (readelf -r executable)

parse relocations with plt address from elf binary and return vector of relocation_t below

  1. typedef struct {
  2. std::intptr_t relocation_offset, relocation_info, relocation_symbol_value;
  3. std::string relocation_type, relocation_symbol_name, relocation_section_name;
  4. std::intptr_t relocation_plt_address;
  5. } relocation_t;

get elf relocations using elf-parser

  1. #include <elf-parser.h>
  2. elf_parser::Elf_parser elf_parser(executable_path);
  3. std::vector<elf_parser::relocation_t> relocs = elf_parser.get_relocations();

see example

Supported Architecture

amd64

Projects using elf-parser

finixbit / ltrace - Library call tracer

finixbit / ftrace - Function call tracer