2023-05-23 06:48:25 +02:00
|
|
|
#pragma once
|
|
|
|
#include "../../Loader/Elf.h"
|
2023-05-23 09:47:56 +02:00
|
|
|
#include <vector>
|
2023-05-23 06:48:25 +02:00
|
|
|
|
2023-06-08 11:51:11 +02:00
|
|
|
struct DynamicModuleInfo;
|
|
|
|
|
2023-05-23 06:48:25 +02:00
|
|
|
/*this struct keeps neccesary info about loaded modules.Main executeable is included too as well*/
|
|
|
|
struct Module
|
|
|
|
{
|
|
|
|
Elf* elf = nullptr;
|
2023-05-23 18:39:24 +02:00
|
|
|
u64 aligned_base_size = 0;
|
|
|
|
u64 base_virtual_addr = 0; //base virtual address
|
2023-05-26 18:22:43 +02:00
|
|
|
|
|
|
|
void* m_dynamic = nullptr;
|
|
|
|
void* m_dynamic_data = nullptr;
|
2023-06-08 11:51:11 +02:00
|
|
|
DynamicModuleInfo* dynamic_info = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DynamicModuleInfo
|
|
|
|
{
|
|
|
|
void* hash_table = nullptr;
|
2023-06-08 12:25:24 +02:00
|
|
|
u64 hash_table_size = 0;
|
|
|
|
|
|
|
|
char* str_table = nullptr;
|
|
|
|
u64 str_table_size = 0;
|
2023-06-08 18:05:03 +02:00
|
|
|
|
|
|
|
elf_symbol* symbol_table = nullptr;
|
|
|
|
u64 symbol_table_total_size = 0;
|
|
|
|
|
|
|
|
u64 init_virtual_addr = 0;
|
|
|
|
u64 fini_virtual_addr = 0;
|
|
|
|
u64 pltgot_virtual_addr = 0;
|
|
|
|
|
2023-05-23 06:48:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Linker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Linker();
|
|
|
|
virtual ~Linker();
|
|
|
|
|
|
|
|
Module* LoadModule(const std::string& elf_name);
|
2023-05-23 09:47:56 +02:00
|
|
|
Module* FindModule(/*u32 id*/);
|
2023-05-23 18:39:24 +02:00
|
|
|
void LoadModuleToMemory(Module* m);
|
2023-06-08 11:51:11 +02:00
|
|
|
void LoadDynamicInfo(Module* program);
|
2023-05-23 09:47:56 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Module*> m_modules;
|
2023-05-23 06:48:25 +02:00
|
|
|
};
|