Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
elf_parser.hpp
Go to the documentation of this file.
1#ifndef ARION_ELF_PARSER_HPP
2#define ARION_ELF_PARSER_HPP
3
4#include <arion/LIEF/ELF/NoteDetails/core/CoreFile.hpp>
5#include <arion/LIEF/LIEF.hpp>
9#include <string>
10#include <vector>
11
12namespace arion
13{
14
15class Arion;
16
33
35extern std::map<LIEF::ELF::Header::FILE_TYPE, ELF_FILE_TYPE> lief_arion_file_types;
36
39{
41 std::vector<BYTE> raw_prstatus;
43 std::vector<BYTE> raw_fpregset;
44
50};
51
54{
56 std::vector<std::unique_ptr<ELF_COREDUMP_THREAD>> threads;
57};
58
73
76{
77 private:
79 std::weak_ptr<Arion> arion;
81 std::shared_ptr<ELF_PARSER_ATTRIBUTES> attrs;
83 bool found_prpsinfo = false;
89 void parse_file_note(const LIEF::ELF::Note &note, std::vector<std::shared_ptr<struct SEGMENT>> segments);
95 void parse_prstatus_note(const LIEF::ELF::Note &note, std::shared_ptr<ELF_PARSER_ATTRIBUTES> attrs);
101 void parse_prpsinfo_note(const LIEF::ELF::Note &note, std::shared_ptr<ELF_PARSER_ATTRIBUTES> attrs);
107 void parse_fpregset_note(const LIEF::ELF::Note &note, std::shared_ptr<ELF_PARSER_ATTRIBUTES> attrs);
108
109 public:
114 ElfCoredumpParser(std::weak_ptr<Arion> arion) : arion(arion) {};
122 std::unique_ptr<LIEF::ELF::Binary> parse_coredump_data(std::unique_ptr<LIEF::ELF::Binary> elf,
123 std::shared_ptr<ELF_PARSER_ATTRIBUTES> attrs,
124 std::vector<std::shared_ptr<struct SEGMENT>> segments);
125};
126
129{
130 private:
132 std::unique_ptr<ElfCoredumpParser> coredump_parser;
138 std::unique_ptr<LIEF::ELF::Binary> parse_general_data(std::unique_ptr<LIEF::ELF::Binary> elf);
144 std::unique_ptr<LIEF::ELF::Binary> parse_segments(std::unique_ptr<LIEF::ELF::Binary> elf);
145
146 public:
153 ElfParser(std::weak_ptr<Arion> arion, std::vector<std::string> args)
155 {
156 this->attrs = std::make_shared<ELF_PARSER_ATTRIBUTES>();
157 if (!args.size())
158 throw arion_exception::InvalidArgumentException("Program arguments must at least contain target name.");
159 this->attrs->path = args.at(0);
160 this->attrs->args = args;
161 };
165 void process();
166};
167
168}; // namespace arion
169
170#endif // ARION_ELF_PARSER_HPP
Helper class responsible for parsing the specific NOTE sections of an ELF core dump file.
Definition elf_parser.hpp:76
std::weak_ptr< Arion > arion
Weak pointer back to the main Arion instance.
Definition elf_parser.hpp:79
void parse_file_note(const LIEF::ELF::Note &note, std::vector< std::shared_ptr< struct SEGMENT > > segments)
void parse_prpsinfo_note(const LIEF::ELF::Note &note, std::shared_ptr< ELF_PARSER_ATTRIBUTES > attrs)
std::unique_ptr< LIEF::ELF::Binary > parse_coredump_data(std::unique_ptr< LIEF::ELF::Binary > elf, std::shared_ptr< ELF_PARSER_ATTRIBUTES > attrs, std::vector< std::shared_ptr< struct SEGMENT > > segments)
ElfCoredumpParser(std::weak_ptr< Arion > arion)
Definition elf_parser.hpp:114
void parse_prstatus_note(const LIEF::ELF::Note &note, std::shared_ptr< ELF_PARSER_ATTRIBUTES > attrs)
void parse_fpregset_note(const LIEF::ELF::Note &note, std::shared_ptr< ELF_PARSER_ATTRIBUTES > attrs)
bool found_prpsinfo
Flag indicating if the NT_PRPSINFO note has been found and parsed.
Definition elf_parser.hpp:83
std::shared_ptr< ELF_PARSER_ATTRIBUTES > attrs
Shared pointer to the parser attributes, including core dump attributes.
Definition elf_parser.hpp:81
Primary class for parsing ELF executables, shared objects, or core dumps. Inherits from ExecutablePar...
Definition elf_parser.hpp:129
ElfParser(std::weak_ptr< Arion > arion, std::vector< std::string > args)
Definition elf_parser.hpp:153
std::unique_ptr< ElfCoredumpParser > coredump_parser
Instance of the core dump parser used if the file type is CORE.
Definition elf_parser.hpp:132
std::unique_ptr< LIEF::ELF::Binary > parse_segments(std::unique_ptr< LIEF::ELF::Binary > elf)
std::unique_ptr< LIEF::ELF::Binary > parse_general_data(std::unique_ptr< LIEF::ELF::Binary > elf)
This class is responsible for extracting specific data from an executable file.
Definition executable_parser.hpp:39
std::shared_ptr< EXECUTABLE_PARSER_ATTRIBUTES > attrs
A structure of attributes which are filled during the parsing.
Definition executable_parser.hpp:44
Thrown when passing an invalid argument to a method.
Definition global_excepts.hpp:73
Definition arch_x86-64.hpp:11
std::map< LIEF::ELF::Header::FILE_TYPE, ELF_FILE_TYPE > lief_arion_file_types
Mapping from LIEF's internal ELF file type enumeration to Arion's ELF_FILE_TYPE.
uint64_t ADDR
Identifies a memory address.
Definition global_defs.hpp:36
ELF_FILE_TYPE
Enumeration of possible ELF file types relevant to the Arion emulator.
Definition elf_parser.hpp:19
@ CORE
Core dump file.
Definition elf_parser.hpp:29
@ DYN
Shared object file (dynamic library).
Definition elf_parser.hpp:27
@ REL
Relocatable file.
Definition elf_parser.hpp:23
@ NUM
Sentinel for the number of types.
Definition elf_parser.hpp:31
@ UNKNOWN_FILE
Unknown ELF file type.
Definition elf_parser.hpp:21
@ EXEC
Executable file.
Definition elf_parser.hpp:25
Structure holding attributes extracted from an ELF core dump, primarily threads' register states.
Definition elf_parser.hpp:54
std::vector< std::unique_ptr< ELF_COREDUMP_THREAD > > threads
List of threads extracted from the core dump.
Definition elf_parser.hpp:56
Structure holding register data for a single thread extracted from an ELF core dump.
Definition elf_parser.hpp:39
std::vector< BYTE > raw_fpregset
Raw byte data of the floating-point register set (fpregset) note.
Definition elf_parser.hpp:43
ELF_COREDUMP_THREAD(std::vector< BYTE > raw_prstatus)
Definition elf_parser.hpp:49
std::vector< BYTE > raw_prstatus
Raw byte data of the general-purpose register set (prstatus) note.
Definition elf_parser.hpp:41
Extended attributes structure for the ELF file parser.
Definition elf_parser.hpp:61
size_t prog_headers_n
Number of program header entries.
Definition elf_parser.hpp:69
std::unique_ptr< ELF_COREDUMP_ATTRS > coredump
Attributes specific to CORE dump files, or null otherwise.
Definition elf_parser.hpp:71
ADDR prog_headers_off
Offset of the program headers table.
Definition elf_parser.hpp:65
size_t prog_headers_entry_sz
Size of a single program header entry.
Definition elf_parser.hpp:67
ELF_FILE_TYPE type
The specific type of the ELF file.
Definition elf_parser.hpp:63
Stores attributes which are filled during the parsing of an executable.
Definition executable_parser.hpp:16