Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
lnx_loader.hpp
Go to the documentation of this file.
1#ifndef ARION_LNX_LOADER_HPP
2#define ARION_LNX_LOADER_HPP
3
7#include <cstdint>
8#include <memory>
9#include <string>
10
11#define LINUX_64_LOAD_ADDR 0x400000
12#define LINUX_64_STACK_ADDR 0x7ffffffde000
13#define LINUX_64_STACK_SZ 0x21000
14
15#define LINUX_32_LOAD_ADDR 0x8040000
16#define LINUX_32_STACK_ADDR 0xfffcf000
17#define LINUX_32_STACK_SZ 0x21000
18
19#define LINUX_STACK_PERMS 6
20
21namespace arion
22{
23
88
99
118
121{
122 private:
128 void setup_auxv(std::unique_ptr<AUXV_PTRS> auxv_ptrs, std::shared_ptr<LNX_LOADER_PARAMS> params);
133 void setup_envp(std::vector<ADDR> envp_ptrs);
138 void setup_argv(std::vector<ADDR> argv_ptrs);
139
140 protected:
142 std::weak_ptr<Arion> arion;
144 const std::vector<std::string> program_args;
146 const std::vector<std::string> program_env;
153 LinuxLoader(std::weak_ptr<Arion> arion, const std::vector<std::string> program_args,
154 const std::vector<std::string> program_env)
161 void write_auxv_entry(AUXV auxv, uint64_t val);
167 virtual void setup_specific_auxv(std::shared_ptr<LNX_LOADER_PARAMS> params, uint16_t arch_sz) = 0;
174 ADDR map_stack(std::shared_ptr<LNX_LOADER_PARAMS> params, std::string path);
180 void init_main_thread(std::shared_ptr<LNX_LOADER_PARAMS> params, ADDR entry_addr);
181
182 public:
187 virtual std::unique_ptr<LNX_LOADER_PARAMS> process() = 0;
188};
189
190}; // namespace arion
191
192#endif // ARION_LNX_LOADER_HPP
Abstract base class for Linux-specific executable loading and setup routines.
Definition lnx_loader.hpp:121
virtual void setup_specific_auxv(std::shared_ptr< LNX_LOADER_PARAMS > params, uint16_t arch_sz)=0
LinuxLoader(std::weak_ptr< Arion > arion, const std::vector< std::string > program_args, const std::vector< std::string > program_env)
Definition lnx_loader.hpp:153
const std::vector< std::string > program_env
Vector of environment variables.
Definition lnx_loader.hpp:146
virtual std::unique_ptr< LNX_LOADER_PARAMS > process()=0
void setup_envp(std::vector< ADDR > envp_ptrs)
void setup_argv(std::vector< ADDR > argv_ptrs)
ADDR map_stack(std::shared_ptr< LNX_LOADER_PARAMS > params, std::string path)
const std::vector< std::string > program_args
Vector of command-line arguments.
Definition lnx_loader.hpp:144
void setup_auxv(std::unique_ptr< AUXV_PTRS > auxv_ptrs, std::shared_ptr< LNX_LOADER_PARAMS > params)
std::weak_ptr< Arion > arion
Weak pointer back to the main Arion instance.
Definition lnx_loader.hpp:142
void write_auxv_entry(AUXV auxv, uint64_t val)
void init_main_thread(std::shared_ptr< LNX_LOADER_PARAMS > params, ADDR entry_addr)
#define ARION_EXPORT
Defines which symbols should be exported from the library.
Definition global_defs.hpp:13
Definition arch_x86-64.hpp:11
AUXV
Enumeration of Auxiliary Vector (AUXV) keys passed by the kernel to the user space.
Definition lnx_loader.hpp:26
@ AT_EUID
Effective User ID.
Definition lnx_loader.hpp:52
@ AT_IGNORE
Entry ignored.
Definition lnx_loader.hpp:30
@ AT_EGID
Effective Group ID.
Definition lnx_loader.hpp:56
@ AT_ENTRY
Entry point of the executable.
Definition lnx_loader.hpp:46
@ AT_GID
Real Group ID.
Definition lnx_loader.hpp:54
@ AT_CLKTCK
Clock tick frequency (jiffies).
Definition lnx_loader.hpp:62
@ AT_HWCAP
Bitmask of CPU hardware capabilities.
Definition lnx_loader.hpp:60
@ AT_SECURE
Non-zero if the process is being run with a security taint.
Definition lnx_loader.hpp:64
@ AT_NULL
End of the auxiliary vector.
Definition lnx_loader.hpp:28
@ AT_NOTELF
Value is non-zero if the executable is not an ELF file.
Definition lnx_loader.hpp:48
@ AT_SYSINFO
Address of a function to call for vsyscall/vdso.
Definition lnx_loader.hpp:82
@ AT_SYSINFO_EHDR
Address of the VDSO/VSYSCALL ELF header.
Definition lnx_loader.hpp:84
@ AT_FLAGS
Flags for the executable.
Definition lnx_loader.hpp:44
@ AT_BASE_PLATFORM
String identifying the base platform.
Definition lnx_loader.hpp:66
@ AT_HWCAP4
Fourth bitmask of CPU hardware capabilities.
Definition lnx_loader.hpp:78
@ AT_PHENT
Size of program header table entry.
Definition lnx_loader.hpp:36
@ AT_RSEQ_ALIGN
Alignment of the rseq structure.
Definition lnx_loader.hpp:74
@ AT_BASE
Base address of the interpreter/dynamic linker.
Definition lnx_loader.hpp:42
@ AT_UID
Real User ID.
Definition lnx_loader.hpp:50
@ AT_MINSIGSTKSZ
Minimum stack size for a signal handler.
Definition lnx_loader.hpp:86
@ AT_EXECFN
Address of the executable's pathname string.
Definition lnx_loader.hpp:80
@ AT_RSEQ_FEATURE_SIZE
Size of the rseq structure.
Definition lnx_loader.hpp:72
@ AT_HWCAP3
Third bitmask of CPU hardware capabilities.
Definition lnx_loader.hpp:76
@ AT_RANDOM
Address of 16 bytes of random data.
Definition lnx_loader.hpp:68
@ AT_PHDR
Program header table address.
Definition lnx_loader.hpp:34
@ AT_PAGESZ
System page size.
Definition lnx_loader.hpp:40
@ AT_HWCAP2
Additional bitmask of CPU hardware capabilities.
Definition lnx_loader.hpp:70
@ AT_PLATFORM
String identifying the kernel platform (e.g., "x86_64").
Definition lnx_loader.hpp:58
@ AT_PHNUM
Number of program header entries.
Definition lnx_loader.hpp:38
@ AT_EXECFD
File descriptor of the executable.
Definition lnx_loader.hpp:32
uint64_t ADDR
Identifies a memory address.
Definition global_defs.hpp:36
Structure holding allocated memory addresses for string data placed on the stack for AUXV.
Definition lnx_loader.hpp:91
ADDR platform_name_addr
Address of the platform string (AT_PLATFORM target).
Definition lnx_loader.hpp:97
ADDR prog_name_addr
Address of the program path string (AT_EXECFN target).
Definition lnx_loader.hpp:95
ADDR random_addr
Address of the random data (AT_RANDOM target).
Definition lnx_loader.hpp:93
Structure holding the key load addresses of the emulated process.
Definition lnx_loader.hpp:102
ADDR vsyscall_address
Base address of the VSYSCALL page.
Definition lnx_loader.hpp:114
ADDR vvar_address
Base address where the VVAR page was mapped.
Definition lnx_loader.hpp:108
ADDR vdso_address
Base address where the VDSO page was mapped.
Definition lnx_loader.hpp:110
ADDR arm_traps_address
Base address of the ARM traps page (32-bit ARM specific).
Definition lnx_loader.hpp:116
ADDR load_address
Base address where the main executable was loaded.
Definition lnx_loader.hpp:104
ADDR stack_address
Base address of the program stack.
Definition lnx_loader.hpp:112
ADDR interp_address
Base address where the dynamic interpreter was loaded.
Definition lnx_loader.hpp:106