Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
elf_loader.hpp
Go to the documentation of this file.
1#ifndef ARION_ELF_LOADER_HPP
2#define ARION_ELF_LOADER_HPP
3
8#include <cstdint>
9#include <memory>
10#include <string>
11
12#define LINUX_64_VVAR_ADDR 0x7ffff7fba000
13#define LINUX_64_VVAR_SZ 0x4000
14#define LINUX_64_VDSO_ADDR 0x7ffff7fbe000
15#define LINUX_64_VDSO_SZ 0x2000
16#define LINUX_64_INTERP_ADDR 0x7ffff7fc0000
17#define LINUX_64_VSYSCALL_ADDR 0xffffffffff600000
18#define LINUX_64_VSYSCALL_ALIGN 0x1000
19
20#define LINUX_32_VVAR_ADDR 0xf7fba000
21#define LINUX_32_VVAR_SZ 0x4000
22#define LINUX_32_VDSO_ADDR 0xf7fbe000
23#define LINUX_32_VDSO_SZ 0x2000
24#define LINUX_32_INTERP_ADDR 0xf7fc0000
25#define LINUX_32_ARM_TRAPS_ADDR 0xffff0000
26#define LINUX_32_ARM_TRAPS_SIZE 0x1000
27#define LINUX_32_ARM_GETTLS_ADDR 0xffff0fe0
28
29#define LINUX_VVAR_PERMS 4
30#define LINUX_VDSO_PERMS 5
31#define LINUX_VSYSCALL_PERMS 1
32#define LINUX_ARM_TRAPS_PERMS 5
33
34#define HEAP_SZ 0x1000
35#define HEAP_PERMS 6
36
37#define LINUX_VDSO_KERNEL_VSYSCALL_OFF 0x570
38
40extern char _binary_vdso_bin_start[];
42extern char _binary_vdso_bin_end[];
43
44namespace arion
45{
46
49{
51 std::string name;
53 off_t off;
55 std::vector<BYTE> code;
56
63 ARM_TRAP(std::string name, off_t off, std::vector<BYTE> code)
64 : name(std::move(name)), off(off), code(std::move(code)) {};
65};
66
69{
70 private:
72 std::shared_ptr<ElfParser> prog_parser, interp_parser;
74 bool is_pie;
83 ADDR map_elf_segments(const std::shared_ptr<ElfParser> parser, ADDR load_addr);
108
109 protected:
115 void setup_specific_auxv(std::shared_ptr<LNX_LOADER_PARAMS> params, uint16_t arch_sz) override;
116
117 public:
126 ElfLoader(std::weak_ptr<Arion> arion, std::shared_ptr<ElfParser> interp_parser,
127 std::shared_ptr<ElfParser> prog_parser, const std::vector<std::string> program_args,
128 const std::vector<std::string> program_env)
137 ElfLoader(std::weak_ptr<Arion> arion, std::shared_ptr<ElfParser> prog_parser,
138 const std::vector<std::string> program_args, const std::vector<std::string> program_env)
139 : ElfLoader(arion, nullptr, std::move(prog_parser), program_args, program_env) {};
144 std::unique_ptr<LNX_LOADER_PARAMS> process() override;
145};
146
147}; // namespace arion
148
149#endif // ARION_ELF_LOADER_HPP
A Linux loader implementation responsible for parsing and mapping ELF binaries (executables and dynam...
Definition elf_loader.hpp:69
std::shared_ptr< ElfParser > interp_parser
Definition elf_loader.hpp:72
void setup_specific_auxv(std::shared_ptr< LNX_LOADER_PARAMS > params, uint16_t arch_sz) override
ElfLoader(std::weak_ptr< Arion > arion, std::shared_ptr< ElfParser > interp_parser, std::shared_ptr< ElfParser > prog_parser, const std::vector< std::string > program_args, const std::vector< std::string > program_env)
Definition elf_loader.hpp:126
ElfLoader(std::weak_ptr< Arion > arion, std::shared_ptr< ElfParser > prog_parser, const std::vector< std::string > program_args, const std::vector< std::string > program_env)
Definition elf_loader.hpp:137
void init_coredump_threads()
bool is_static
Flag indicating if the program is statically linked.
Definition elf_loader.hpp:76
std::shared_ptr< ElfParser > prog_parser
ELF parser for the program interpreter (dynamic linker).
Definition elf_loader.hpp:72
ADDR map_elf_segments(const std::shared_ptr< ElfParser > parser, ADDR load_addr)
std::unique_ptr< LNX_LOADER_PARAMS > process() override
bool is_pie
Flag indicating if the program is Position-Independent Executable (PIE).
Definition elf_loader.hpp:74
Abstract base class for Linux-specific executable loading and setup routines.
Definition lnx_loader.hpp:121
const std::vector< std::string > program_env
Vector of environment variables.
Definition lnx_loader.hpp:146
const std::vector< std::string > program_args
Vector of command-line arguments.
Definition lnx_loader.hpp:144
char _binary_vdso_bin_start[]
External symbol indicating the start of the embedded VDSO binary data.
char _binary_vdso_bin_end[]
External symbol indicating the end of the embedded VDSO binary data.
Definition arch_x86-64.hpp:11
uint64_t ADDR
Identifies a memory address.
Definition global_defs.hpp:36
Structure representing a kernel trap entry for the 32-bit ARM architecture.
Definition elf_loader.hpp:49
ARM_TRAP(std::string name, off_t off, std::vector< BYTE > code)
Definition elf_loader.hpp:63
std::vector< BYTE > code
The actual machine code bytes of the trap.
Definition elf_loader.hpp:55
std::string name
Name of the trap function (e.g., syscall).
Definition elf_loader.hpp:51
off_t off
Offset within the ARM traps page.
Definition elf_loader.hpp:53