From 3a6b35457149858b70ad048941e238aab2f6a71d Mon Sep 17 00:00:00 2001 From: Quentin <837334+xiaoxiao921@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:59:17 +0200 Subject: [PATCH] feat(debug): dump_entry_points (#3405) --- src/util/system.hpp | 94 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/src/util/system.hpp b/src/util/system.hpp index ef614a1a..faffa44f 100644 --- a/src/util/system.hpp +++ b/src/util/system.hpp @@ -7,22 +7,90 @@ namespace big::system { inline void dump_entry_points() { - // TODO! -#if 0 - DWORD64 base_address = memory::module("GTA5.exe").begin().as(); - - 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) + try { - auto address = g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, map.second); + 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; + }; - file << std::hex << std::uppercase << "0x" << map.first << " : GTA5.exe + 0x" << (DWORD64)address - base_address << std::endl; + std::unordered_map 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 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 (size_t i = 0; i < g_crossmap.size(); i++) + { + const auto address = (uintptr_t)g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, g_crossmap[i]); + + // 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(); + LOG(INFO) << "Done dumping native entrypoints."; + } + catch (const std::exception& e) + { + LOG(FATAL) << e.what(); + } + catch (...) + { + LOG(FATAL) << "Unknown exception."; } - - file.close(); -#endif } inline uintptr_t get_relative_address(void* ptr)