feat(debug): dump_entry_points (#3405)

This commit is contained in:
Quentin 2024-07-23 12:59:17 +02:00 committed by GitHub
parent f62c8c875e
commit 3a6b354571
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,22 +7,90 @@ namespace big::system
{
inline void dump_entry_points()
{
// TODO!
#if 0
DWORD64 base_address = memory::module("GTA5.exe").begin().as<DWORD64>();
try
{
const auto hex_string_to_integer = [](const std::string& hex_str) -> uint64_t {
uint64_t result;
std::stringstream ss;
ss << std::hex << hex_str;
ss >> result;
return result;
};
std::unordered_map<uint64_t, uint64_t> current_native_hash_to_original;
{
const auto crossmap_txt_file_path = g_file_manager.get_project_file("./crossmap.txt").get_path();
auto crossmap_txt_file = std::ifstream(crossmap_txt_file_path);
if (!crossmap_txt_file.is_open())
{
LOG(FATAL) << "Need the crossmap.txt file from YimMenu repo. Put into %appdata%/YimMenu folder.";
return;
}
std::string line;
while (std::getline(crossmap_txt_file, line))
{
std::stringstream ss(line);
std::string original, current;
if (std::getline(ss, original, ',') && std::getline(ss, current, '\n'))
{
current_native_hash_to_original[hex_string_to_integer(current)] = hex_string_to_integer(original);
}
}
crossmap_txt_file.close();
}
std::unordered_map<uint64_t, std::string> original_native_hash_to_name;
{
const auto native_json_file_path = g_file_manager.get_project_file("./natives.json").get_path();
auto native_json_file = std::ifstream(native_json_file_path);
if (!native_json_file.is_open())
{
LOG(FATAL) << "Need the natives.json file from YimMenu repo. Put into %appdata%/YimMenu folder.";
return;
}
nlohmann::json native_json = nlohmann::json::parse(native_json_file);
for (auto& [native_namespace, natives] : native_json.items())
{
for (auto& [native_original_hash, native_info] : natives.items())
{
original_native_hash_to_name[hex_string_to_integer(native_original_hash)] = native_info["name"];
}
}
native_json_file.close();
}
const auto file_path = g_file_manager.get_project_file("./entrypoints.txt");
auto file = std::ofstream(file_path.get_path(), std::ios::out | std::ios::trunc);
for (auto& map : g_crossmap)
for (size_t i = 0; i < g_crossmap.size(); i++)
{
auto address = g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, map.second);
const auto address = (uintptr_t)g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, g_crossmap[i]);
file << std::hex << std::uppercase << "0x" << map.first << " : GTA5.exe + 0x" << (DWORD64)address - base_address << std::endl;
// clang-format off
file <<
original_native_hash_to_name[current_native_hash_to_original[g_crossmap[i]]] <<
" | " <<
std::hex << std::uppercase << (((DWORD64)address) - (DWORD64)GetModuleHandleA(0)) << std::dec << std::nouppercase <<
std::endl;
// clang-format on
}
file.close();
#endif
LOG(INFO) << "Done dumping native entrypoints.";
}
catch (const std::exception& e)
{
LOG(FATAL) << e.what();
}
catch (...)
{
LOG(FATAL) << "Unknown exception.";
}
}
inline uintptr_t get_relative_address(void* ptr)