From 672e2b2d77941b61dfaf753f80afae90241ee080 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 8 Jun 2023 12:51:11 +0300 Subject: [PATCH] initial dynamic loader , parsing DT_HASH atm --- src/Core/PS4/Linker.cpp | 19 +++++++++++++++++++ src/Core/PS4/Linker.h | 9 +++++++++ src/Loader/Elf.h | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index 0cc7e646..8476bdbb 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -47,6 +47,7 @@ Module* Linker::LoadModule(const std::string& elf_name) if (m->elf->isElfFile()) { LoadModuleToMemory(m); + LoadDynamicInfo(m); } else { @@ -157,4 +158,22 @@ void Linker::LoadModuleToMemory(Module* m) offset += instruction.info.length; runtime_address += instruction.info.length; } +} + +void Linker::LoadDynamicInfo(Module* m) +{ + m->dynamic_info = new DynamicModuleInfo; + + for (const auto* dyn = static_cast(m->m_dynamic); dyn->d_tag != DT_NULL; dyn++) + { + switch (dyn->d_tag) + { + case DT_OS_HASH: + m->dynamic_info->hash_table = reinterpret_cast(static_cast(m->m_dynamic_data) + dyn->d_un.d_ptr); + break; + default: + LOG_INFO_IF(debug_loader, "unsupported dynamic tag ..........: {:#018x}\n", dyn->d_tag); + } + + } } \ No newline at end of file diff --git a/src/Core/PS4/Linker.h b/src/Core/PS4/Linker.h index 002dc30f..7add71c2 100644 --- a/src/Core/PS4/Linker.h +++ b/src/Core/PS4/Linker.h @@ -2,6 +2,8 @@ #include "../../Loader/Elf.h" #include +struct DynamicModuleInfo; + /*this struct keeps neccesary info about loaded modules.Main executeable is included too as well*/ struct Module { @@ -11,6 +13,12 @@ struct Module void* m_dynamic = nullptr; void* m_dynamic_data = nullptr; + DynamicModuleInfo* dynamic_info = nullptr; +}; + +struct DynamicModuleInfo +{ + void* hash_table = nullptr; }; class Linker @@ -22,6 +30,7 @@ public: Module* LoadModule(const std::string& elf_name); Module* FindModule(/*u32 id*/); void LoadModuleToMemory(Module* m); + void LoadDynamicInfo(Module* program); private: std::vector m_modules; diff --git a/src/Loader/Elf.h b/src/Loader/Elf.h index dbe7c9c3..b425e794 100644 --- a/src/Loader/Elf.h +++ b/src/Loader/Elf.h @@ -323,6 +323,19 @@ struct elf_program_id_header u64 firmver; u08 digest[32]; }; + +constexpr s64 DT_NULL = 0; +constexpr s64 DT_OS_HASH = 0x61000025; + +struct elf_dynamic +{ + s64 d_tag; + union + { + u64 d_val; + u64 d_ptr; + } d_un; +}; class Elf { public: