Symbol resolver added

This commit is contained in:
georgemoralis 2023-06-26 18:12:19 +03:00
parent e7649001e1
commit b8c542805f
5 changed files with 78 additions and 1 deletions

View File

@ -34,7 +34,7 @@ add_executable(shadps4
src/Core/Memory.h
src/Core/PS4/Linker.cpp
src/Core/PS4/Linker.h
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h")
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp")
find_package(OpenGL REQUIRED)

View File

@ -4,6 +4,7 @@
#include "../../Util/Disassembler.h"
#include "../../Util/StringUtil.h"
#include "Util/aerolib.h"
#include "Loader/SymbolsResolver.h"
constexpr bool debug_loader = true;
@ -414,6 +415,9 @@ void Linker::LoadSymbols(Module* m)
LOG_INFO_IF(debug_loader, "Symbol table not found!\n");
return;
}
m->export_sym = new SymbolsResolver;
m->import_sym = new SymbolsResolver;
for (auto* sym = m->dynamic_info->symbol_table;
reinterpret_cast<uint8_t*>(sym) < reinterpret_cast<uint8_t*>(m->dynamic_info->symbol_table) + m->dynamic_info->symbol_table_total_size;
sym++)
@ -466,6 +470,25 @@ void Linker::LoadSymbols(Module* m)
{
nidName = "UNK";
}
SymbolRes sym_r{};
sym_r.name = ids.at(0);
sym_r.nidName = nidName;
sym_r.library = library->name;
sym_r.library_version = library->version;
sym_r.module = module->name;
sym_r.module_version_major = module->version_major;
sym_r.module_version_minor = module->version_minor;
sym_r.type = type;
if (is_sym_export)
{
m->export_sym->AddSymbol(sym_r, sym->st_value + m->base_virtual_addr);
}
else
{
m->import_sym->AddSymbol(sym_r,0);
}
LOG_INFO_IF(debug_loader, "name {} function {} library {} module {} bind {} type {} visibility {}\n", ids.at(0),nidName,library->name, module->name, bind, type, visibility);
}

View File

@ -2,6 +2,7 @@
#include <vector>
#include "Loader/Elf.h"
#include "Loader/SymbolsResolver.h"
struct DynamicModuleInfo;
@ -15,6 +16,9 @@ struct Module
void* m_dynamic = nullptr;
void* m_dynamic_data = nullptr;
DynamicModuleInfo* dynamic_info = nullptr;
SymbolsResolver* export_sym = nullptr;
SymbolsResolver* import_sym = nullptr;
};
struct ModuleInfo

View File

@ -0,0 +1,13 @@
#include "../../../types.h"
#include "SymbolsResolver.h"
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr)
{
SymbolRecord r{};
char str[256];
sprintf(str, "%s (%s)[%s_v%d][%s_v%d.%d]", s.name.c_str(),s.nidName.c_str(), s.library.c_str(), s.library_version, s.module.c_str(),s.module_version_major, s.module_version_minor);
r.name = std::string(str);
r.virtual_address = virtual_addr;
m_symbols.push_back(r);
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include "../../../types.h"
struct SymbolRecord
{
std::string name;
u64 virtual_address;
};
struct SymbolRes
{
std::string name;
std::string nidName;
std::string library;
u16 library_version;
std::string module;
u08 module_version_major;
u08 module_version_minor;
u32 type;
};
class SymbolsResolver
{
public:
SymbolsResolver() = default;
virtual ~SymbolsResolver() = default;
void AddSymbol(const SymbolRes& s, u64 virtual_addr);
private:
std::vector<SymbolRecord> m_symbols;
};