Merge pull request #5183 from lioncash/sig
MEGASignatureDB: Minor changes
This commit is contained in:
commit
9930052725
|
@ -8,6 +8,8 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <sstream>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
@ -16,66 +18,11 @@
|
||||||
#include "Core/PowerPC/PPCSymbolDB.h"
|
#include "Core/PowerPC/PPCSymbolDB.h"
|
||||||
#include "Core/PowerPC/PowerPC.h"
|
#include "Core/PowerPC/PowerPC.h"
|
||||||
|
|
||||||
static constexpr size_t INSTRUCTION_HEXSTRING_LENGTH = 8;
|
namespace
|
||||||
|
|
||||||
MEGASignatureDB::MEGASignatureDB() = default;
|
|
||||||
MEGASignatureDB::~MEGASignatureDB() = default;
|
|
||||||
|
|
||||||
bool MEGASignatureDB::Load(const std::string& file_path)
|
|
||||||
{
|
{
|
||||||
std::string line;
|
constexpr size_t INSTRUCTION_HEXSTRING_LENGTH = 8;
|
||||||
std::ifstream ifs;
|
|
||||||
OpenFStream(ifs, file_path, std::ios_base::in);
|
|
||||||
|
|
||||||
if (!ifs)
|
bool GetCode(MEGASignature* sig, std::istringstream* iss)
|
||||||
return false;
|
|
||||||
for (size_t i = 1; std::getline(ifs, line); ++i)
|
|
||||||
{
|
|
||||||
std::istringstream iss(line);
|
|
||||||
MEGASignature sig;
|
|
||||||
|
|
||||||
if (GetCode(&sig, &iss) && GetName(&sig, &iss) && GetRefs(&sig, &iss))
|
|
||||||
{
|
|
||||||
m_signatures.push_back(sig);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WARN_LOG(OSHLE, "MEGA database failed to parse line %zu", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEGASignatureDB::Apply(PPCSymbolDB* symbol_db) const
|
|
||||||
{
|
|
||||||
for (auto& it : symbol_db->AccessSymbols())
|
|
||||||
{
|
|
||||||
u32 hash = it.first;
|
|
||||||
auto& symbol = it.second;
|
|
||||||
for (const auto& sig : m_signatures)
|
|
||||||
{
|
|
||||||
if (Compare(symbol.address, symbol.size, sig))
|
|
||||||
{
|
|
||||||
symbol.name = sig.name;
|
|
||||||
INFO_LOG(OSHLE, "Found %s at %08x (size: %08x)!", sig.name.c_str(), symbol.address,
|
|
||||||
symbol.size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
symbol_db->Index();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEGASignatureDB::List() const
|
|
||||||
{
|
|
||||||
for (const auto& entry : m_signatures)
|
|
||||||
{
|
|
||||||
DEBUG_LOG(OSHLE, "%s : %zu bytes", entry.name.c_str(), entry.code.size() * sizeof(u32));
|
|
||||||
}
|
|
||||||
INFO_LOG(OSHLE, "%zu functions known in current MEGA database.", m_signatures.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MEGASignatureDB::GetCode(MEGASignature* sig, std::istringstream* iss) const
|
|
||||||
{
|
{
|
||||||
std::string code;
|
std::string code;
|
||||||
if ((*iss >> code) && (code.length() % INSTRUCTION_HEXSTRING_LENGTH) == 0)
|
if ((*iss >> code) && (code.length() % INSTRUCTION_HEXSTRING_LENGTH) == 0)
|
||||||
|
@ -99,7 +46,7 @@ bool MEGASignatureDB::GetCode(MEGASignature* sig, std::istringstream* iss) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MEGASignatureDB::GetFunctionName(std::istringstream* iss, std::string* name) const
|
bool GetFunctionName(std::istringstream* iss, std::string* name)
|
||||||
{
|
{
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
|
||||||
|
@ -117,13 +64,13 @@ bool MEGASignatureDB::GetFunctionName(std::istringstream* iss, std::string* name
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MEGASignatureDB::GetName(MEGASignature* sig, std::istringstream* iss) const
|
bool GetName(MEGASignature* sig, std::istringstream* iss)
|
||||||
{
|
{
|
||||||
std::string unknown;
|
std::string unknown;
|
||||||
return (*iss >> unknown) && GetFunctionName(iss, &sig->name);
|
return (*iss >> unknown) && GetFunctionName(iss, &sig->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MEGASignatureDB::GetRefs(MEGASignature* sig, std::istringstream* iss) const
|
bool GetRefs(MEGASignature* sig, std::istringstream* iss)
|
||||||
{
|
{
|
||||||
std::string num, ref;
|
std::string num, ref;
|
||||||
u32 ref_count = 1;
|
u32 ref_count = 1;
|
||||||
|
@ -145,7 +92,7 @@ bool MEGASignatureDB::GetRefs(MEGASignature* sig, std::istringstream* iss) const
|
||||||
WARN_LOG(OSHLE, "MEGA database failed to parse reference %u name", ref_count);
|
WARN_LOG(OSHLE, "MEGA database failed to parse reference %u name", ref_count);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sig->refs.emplace_back(static_cast<u32>(offset), ref);
|
sig->refs.emplace_back(static_cast<u32>(offset), std::move(ref));
|
||||||
|
|
||||||
ref_count += 1;
|
ref_count += 1;
|
||||||
num.clear();
|
num.clear();
|
||||||
|
@ -154,7 +101,7 @@ bool MEGASignatureDB::GetRefs(MEGASignature* sig, std::istringstream* iss) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MEGASignatureDB::Compare(u32 address, u32 size, const MEGASignature& sig) const
|
bool Compare(u32 address, u32 size, const MEGASignature& sig)
|
||||||
{
|
{
|
||||||
if (size != sig.code.size() * sizeof(u32))
|
if (size != sig.code.size() * sizeof(u32))
|
||||||
return false;
|
return false;
|
||||||
|
@ -167,3 +114,61 @@ bool MEGASignatureDB::Compare(u32 address, u32 size, const MEGASignature& sig) c
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
|
MEGASignatureDB::MEGASignatureDB() = default;
|
||||||
|
MEGASignatureDB::~MEGASignatureDB() = default;
|
||||||
|
|
||||||
|
bool MEGASignatureDB::Load(const std::string& file_path)
|
||||||
|
{
|
||||||
|
std::ifstream ifs;
|
||||||
|
OpenFStream(ifs, file_path, std::ios_base::in);
|
||||||
|
|
||||||
|
if (!ifs)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
for (size_t i = 1; std::getline(ifs, line); ++i)
|
||||||
|
{
|
||||||
|
std::istringstream iss(line);
|
||||||
|
MEGASignature sig;
|
||||||
|
|
||||||
|
if (GetCode(&sig, &iss) && GetName(&sig, &iss) && GetRefs(&sig, &iss))
|
||||||
|
{
|
||||||
|
m_signatures.push_back(std::move(sig));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WARN_LOG(OSHLE, "MEGA database failed to parse line %zu", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MEGASignatureDB::Apply(PPCSymbolDB* symbol_db) const
|
||||||
|
{
|
||||||
|
for (auto& it : symbol_db->AccessSymbols())
|
||||||
|
{
|
||||||
|
auto& symbol = it.second;
|
||||||
|
for (const auto& sig : m_signatures)
|
||||||
|
{
|
||||||
|
if (Compare(symbol.address, symbol.size, sig))
|
||||||
|
{
|
||||||
|
symbol.name = sig.name;
|
||||||
|
INFO_LOG(OSHLE, "Found %s at %08x (size: %08x)!", sig.name.c_str(), symbol.address,
|
||||||
|
symbol.size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
symbol_db->Index();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MEGASignatureDB::List() const
|
||||||
|
{
|
||||||
|
for (const auto& entry : m_signatures)
|
||||||
|
{
|
||||||
|
DEBUG_LOG(OSHLE, "%s : %zu bytes", entry.name.c_str(), entry.code.size() * sizeof(u32));
|
||||||
|
}
|
||||||
|
INFO_LOG(OSHLE, "%zu functions known in current MEGA database.", m_signatures.size());
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -47,11 +46,5 @@ public:
|
||||||
void List() const;
|
void List() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetCode(MEGASignature* sig, std::istringstream* iss) const;
|
|
||||||
bool GetFunctionName(std::istringstream* iss, std::string* name) const;
|
|
||||||
bool GetName(MEGASignature* sig, std::istringstream* iss) const;
|
|
||||||
bool GetRefs(MEGASignature* sig, std::istringstream* iss) const;
|
|
||||||
bool Compare(u32 address, u32 size, const MEGASignature& sig) const;
|
|
||||||
|
|
||||||
std::vector<MEGASignature> m_signatures;
|
std::vector<MEGASignature> m_signatures;
|
||||||
};
|
};
|
||||||
|
|
|
@ -466,7 +466,7 @@ wxMenu* MainMenuBar::CreateSymbolsMenu() const
|
||||||
"used in multiple games, by loading them from a .dsy file."));
|
"used in multiple games, by loading them from a .dsy file."));
|
||||||
symbols_menu->Append(
|
symbols_menu->Append(
|
||||||
IDM_USE_MEGA_SIGNATURE_FILE, _("Apply &MEGA Signature File..."),
|
IDM_USE_MEGA_SIGNATURE_FILE, _("Apply &MEGA Signature File..."),
|
||||||
_("Must use Generate Symbol Map first! Recognise names of any standard library functions "
|
_("Must use Generate Symbols first! Recognise names of any standard library functions "
|
||||||
"used in multiple games, by loading them from a .mega file."));
|
"used in multiple games, by loading them from a .mega file."));
|
||||||
symbols_menu->AppendSeparator();
|
symbols_menu->AppendSeparator();
|
||||||
symbols_menu->Append(IDM_PATCH_HLE_FUNCTIONS, _("&Patch HLE Functions"));
|
symbols_menu->Append(IDM_PATCH_HLE_FUNCTIONS, _("&Patch HLE Functions"));
|
||||||
|
|
Loading…
Reference in New Issue