57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#include "tool.hpp"
|
|
#include <CLI11.hpp>
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
|
|
static std::string output_file = "hooks.def";
|
|
|
|
bool generateHooksFile(const std::string &output_filepath) {
|
|
Options &options = Options::get();
|
|
|
|
try {
|
|
DatabaseManager db(options.db_path);
|
|
|
|
std::vector<FunctionInfo> fix_functions = db.getFunctionsByType(FileType::Fix);
|
|
|
|
std::ofstream output_stream(output_filepath);
|
|
if (!output_stream.is_open()) {
|
|
spdlog::error("Could not open output file {}", output_filepath);
|
|
return false;
|
|
}
|
|
|
|
spdlog::info("Generating hooks file: {}", output_filepath);
|
|
|
|
for (const auto &func : fix_functions) {
|
|
// Extract just the filename from the full path
|
|
std::string filename = std::filesystem::path(func.filepath).filename().string();
|
|
|
|
output_stream << "HOOK(0x" << func.address << ", " << func.name << ") // " << filename << std::endl;
|
|
|
|
spdlog::debug("Added hook: {} {} from {}", func.address, func.name, filename);
|
|
}
|
|
|
|
output_stream.close();
|
|
|
|
spdlog::info("Generated {} hooks in {}", fix_functions.size(), output_filepath);
|
|
return true;
|
|
|
|
} catch (const std::exception &e) {
|
|
spdlog::error("Error generating hooks file: {}", e.what());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void register_cmd_hooks(CLI::App &app) {
|
|
auto cmd = app.add_subcommand("hooks", "Generate hooks file for Fix-type functions");
|
|
cmd->add_option("-o,--output", output_file, "Output file for hooks")
|
|
->default_val("hooks.def");
|
|
cmd->final_callback([]() {
|
|
spdlog::info("=== Generating hooks file: {} ===", output_file);
|
|
if (generateHooksFile(output_file)) {
|
|
spdlog::info("Successfully generated hooks file");
|
|
} else {
|
|
spdlog::error("Failed to generate hooks file");
|
|
}
|
|
});
|
|
}
|