2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
#include "common/io_file.h"
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/logging/log.h"
|
2024-03-11 12:26:33 +01:00
|
|
|
#include "common/string_util.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "common/types.h"
|
2024-03-11 12:26:33 +01:00
|
|
|
#include "core/aerolib/aerolib.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "core/loader/symbols_resolver.h"
|
2023-06-26 17:12:19 +02:00
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
namespace Core::Loader {
|
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
void SymbolsResolver::AddSymbol(const SymbolResolver& s, u64 virtual_addr) {
|
2024-03-25 08:46:36 +01:00
|
|
|
SymbolRecord& r = m_symbols.emplace_back();
|
2023-07-11 17:50:29 +02:00
|
|
|
r.name = GenerateName(s);
|
2024-02-23 21:57:57 +01:00
|
|
|
r.virtual_address = virtual_addr;
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
std::string SymbolsResolver::GenerateName(const SymbolResolver& s) {
|
|
|
|
return fmt::format("{}#{}#{}#{}#{}#{}#{}", s.name, s.library, s.library_version, s.module,
|
|
|
|
s.module_version_major, s.module_version_minor, SymbolTypeToS(s.type));
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolResolver& s) const {
|
2024-02-23 21:57:57 +01:00
|
|
|
const std::string name = GenerateName(s);
|
2023-10-26 22:29:05 +02:00
|
|
|
for (u32 i = 0; i < m_symbols.size(); i++) {
|
2024-03-25 08:46:36 +01:00
|
|
|
if (m_symbols[i].name == name) {
|
2023-10-26 22:29:05 +02:00
|
|
|
return &m_symbols[i];
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-26 22:29:05 +02:00
|
|
|
|
2024-03-26 18:51:10 +01:00
|
|
|
// LOG_INFO(Core_Linker, "Unresolved! {}", name);
|
2024-02-23 21:57:57 +01:00
|
|
|
return nullptr;
|
2023-10-26 22:29:05 +02:00
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
void SymbolsResolver::DebugDump(const std::filesystem::path& file_name) {
|
|
|
|
Common::FS::IOFile f{file_name, Common::FS::FileAccessMode::Write,
|
|
|
|
Common::FS::FileType::TextFile};
|
|
|
|
for (const auto& symbol : m_symbols) {
|
|
|
|
const auto ids = Common::SplitString(symbol.name, '#');
|
|
|
|
std::string nidName = "";
|
|
|
|
auto aeronid = AeroLib::FindByNid(ids.at(0).c_str());
|
|
|
|
if (aeronid != nullptr) {
|
|
|
|
nidName = aeronid->name;
|
|
|
|
} else {
|
|
|
|
nidName = "UNK";
|
|
|
|
}
|
2024-03-26 11:33:00 +01:00
|
|
|
f.WriteString(
|
|
|
|
fmt::format("0x{:<20x} {:<16} {:<60} {:<30} {:<2} {:<30} {:<2} {:<2} {:<10}\n",
|
|
|
|
symbol.virtual_address, ids.at(0), nidName, ids.at(1), ids.at(2), ids.at(3),
|
|
|
|
ids.at(4), ids.at(5), ids.at(6)));
|
2024-03-11 12:26:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-26 11:57:18 +01:00
|
|
|
int SymbolsResolver::GetSize() {
|
|
|
|
return m_symbols.size();
|
|
|
|
}
|
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
} // namespace Core::Loader
|